set:
用于修改表中的数据,自动去掉没用的逗号。
实例讲解:
- 编写接口
int updateBook(Map map);
- 编写xml配置文件
<update id="updateBook" parameterType="map" >
update book
<set>
<if test="name!=null">
name=#{name},
</if>
<if test="author!=null">
author=#{author}
</if>
</set>
where id=#{id}
</update>
- 测试
@org.junit.Test
public void testIf(){
SqlSession sqlSession=MyBatisUtils.getSqlSession();
BookMapper bookMapper=sqlSession.getMapper(BookMapper.class);
HashMap map=new HashMap();
map.put("name","三国");
map.put("author","娃哈");
map.put("id","78eb87ec.c6ac.4b1c.881a.aabccff3a670");
bookMapper.updateBook(map);
sqlSession.close();
}