会员
周边
新闻
博问
融资
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
huaobin
博客园
首页
新随笔
联系
订阅
管理
set
set标签用于更新语句,当同事要更新多个字段时,我们需要留意当前是否是最后一个set,避免在后面出现
,
符号,使用set标签后可自动去除最后的逗号
mapper:
<
update
id=
"updateProductTest"
parameterType=
"products"> update products
<
set>
<
if
test=
"pname != null and pname != ''"> pname = #{pname},
</
if>
<
if
test=
"price != null and price > 0"> price = #{price},
</
if>
<
if
test=
"pdate != null"> pdate = #{pdate},
</
if>
<
if
test=
"cid != null and cid != ''"> cid = #{cid},
</
if>
</
set> where pid = #{pid}
</
update>
测试代码:
@Test
public
void
updateTest2
(){ SqlSession session = factory.openSession(); ProductsMapper mapper = session.getMapper(ProductsMapper.class);
//获取已有对象 Products product = mapper.selectProductById(
7); product.setPname(
"云南小土豆"); product.setPrice(
10.5f);
//执行更新 mapper.updateProductTest(product); System.out.println(product); session.commit(); session.close(); }
posted @
2020-10-06 11:58
青竹之下
阅读(
115
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告