mybatis之sql标签

if标签

<if test="id != null">

and id = #{id}

</if>

注意下面的id必须是字符串类型,因为字符串才有trim()方法。

<if test="id != null and id.trim()!=''">

and id = #{id}

</if>

choose标签

insert into tb_user VALUES (

<choose>

<when test="user.id != null">

#{user.id},

</when>

<otherwise>

null,

</otherwise>

</choose>

#{user.userName},#{user.password},#{user.name},#{user.age},#{user.sex},#{user.birthday},#{user.created},#{user.updated})

Set标签:

注意set标签作用是可以结合if标签,如果某字段为null,则不修改这个字段

<update id="updateUser">

update tb_user

<set>

<if test="userName!=null and userName.trim()!=''">

user_name = #{userName},

</if>

<if test="password!=null and password.trim()!=''">

password = #{password},

</if>

updated = now()

</set>

where id = #{id}

</update>

where标签:

update tb_user

<set>

age = #{user.age},

birthday = #{user.birthday},

updated = #{user.updated}

</set>

<where>

id = #{user.id}

</where>

foreach标签:

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值