MyBatis更新数据(输入参数类型为Map)

public boolean updateFpkjByCondition(Map params) {
    Map<String , Object> map = new HashMap<>();
    map.put("params" , params);
    return getMybatisDao().execute(FpkjConstant.UPDATEFPKJBYCONDITION, map) == 1;
}
"updateFpkjByCondition" parameterType="java.util.Map">
        UPDATE fp_kj
        SET
        <foreach item="value" index="key" collection="params" separator=",">
          <if test="key != 'ID'">
              ${key} = #{value}
          if>
        foreach>
        WHERE
        <foreach item="value" index="key" collection="params" separator=",">
            <if test="key == 'ID'">
                ID = #{value}
            if>
        foreach>
private ApplicationContext applicationContext;

@Before
public void setUp() throws Exception{
    applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
}

@Test
public void testUpdateFpkjByCondition(){
    IFpkjService fpkjService = (IFpkjService) applicationContext.getBean("fpkjService");
    Map map = new HashMap<>();
    map.put("ID", "100003");
    map.put("FPQQLSH","2");
    map.put("KPRQ", "20090101010101");
    boolean b = fpkjService.updateFpkjByCondition(map);
    System.out.println(b);
}

你可能感兴趣的:(基础知识,J2EE)