mybatis if标签的判断是否等于1,0

正确写法:

<if test=" xxx==1 "> 或者 <if test=" xxx=='1'.toString() "> 或者 <if test=' xxx=="1" '>

错误写法

<if test=" xxx=='1' ">

如果判断条件是数字,则不能加单引号,否则将会不生效!

 

拓展:

mybatis源码中,会把 0 和 空字符串都转成 0.00,

所以当<if test=" xxx==0 ">时,mybatis默认会把0等价于空字符串,所以不会生效

正确写法: <if test=" xxx=='0'.toString() "> 或者 <if test=' xxx=="0" '>

posted @ 2023-06-08 16:31  Li_ll  Views(1676)  Comments(0Edit  收藏  举报