Mybatis if test 判断数字时需要注意
来源:互联网 发布:java分布式开发面试题 编辑:程序博客网 时间:2024/06/05 16:46
引言
今天小编在mybatis中编写动态sql的时候,使用到了if标签来判断是否需要拼接查询条件,但是在判断数值类型的字段的时候出现了意外,请看代码
<select id="getPartnerList" parameterType="com.acs.saasdb.account.entity.Partner" resultMap="BaseResultMap"> SELECT * FROM acs_partner <where> (partner_id IN (-1,8) OR id=partner_id) <if test="partner.partnerName !=null and partner.partnerName!=''"> AND partner_name LIKE CONCAT(CONCAT('%', #{partner.partnerName}),'%') </if> <if test="partner.companyType !=null and partner.companyType!='' or partner.companyType==0"> AND company_type =#{partner.companyType} </if> <if test="partner.contactName !=null and partner.contactName !='' "> AND contact_name LIKE CONCAT (CONCAT ('%',#{partner.contactName}),'%') </if> <if test="partner.contactMobile !=null and partner.contactMobile !='' "> AND contact_mobile LIKE CONCAT (CONCAT ('%',#{partner.contactMobile}),'%') </if> <if test="partner.businessType !=null and partner.businessType!='' or partner.businessType==0"> AND business_type =#{partner.businessType} </if> <if test="partner.createCompany !=null and partner.createCompany !='' "> AND create_company =#{partner.createCompany} </if> <if test="partner.state !=null and partner.state !='' "> AND state =#{partner.state} </if> </where> ORDER BY create_time DESC limit #{page.offset},#{page.limit} </select>
从上面的代码中我们可以看到两个比较繁琐的写法就是,上面红色的部分,这是因为这两个字段是数字类型,当值为0时,如果我们按照判断字符的方式来写的话,不会进入到if标签中,这是mybatis中if标签比较恶心的一个地方,在这和大家分享。
mybatis做if判断注意 mybatis做if 判断 注意:下面这种写法只适用于 id 类型为字符串. <if test="id != null and id != '' "> id = #{id} </if> 如果id类型为int 当id=0时 这个判断不会进入.可以这样写<if test="id != null and id != '' or id==0">
阅读全文
0 0
- Mybatis if test 判断数字时需要注意
- Mybatis if test 判断数字时需要注意
- Mybatis if test 判断数字时需要注意
- Mybatis if test 判断数字时需要注意
- Mybatis if test 动态判断数字时需要注意的问题
- Mybatis <if test> 判断数字时的问题
- Mybatis中 if test 判断数值字符串注意项
- mybatis if标签test 判断数字遇到的问题
- mybatis作if判断注意
- mybatis 里面使用<if test=""> 判断,当后台传的值是数字字符串时,怎么处理
- MyBatis if test 字符串判断问题
- mybatis的<if test> 条件判断
- MyBatis if test 字符串判断问题
- mybatis的<if test> 条件判断
- mybatis if test 字符串判断问题
- mybatis 中<if test="">test中的判断条件 ognl
- MyBatis test 数字判断没生效
- jstl中使用做判断用的标签属性test时需要注意的
- idea中Terminal终端无法执行GIT命令: touch README.md问题解决
- 如何在mapper传入list参数
- Argument for @NotNull parameter 'name' of com/android/tools/idea/welcome/Platform.<init> must not be
- 数据产品面试准备
- tornado使用post方法
- Mybatis if test 判断数字时需要注意
- python内存机制
- 自定义标签实现分页查询1.0版本
- malloc和free(3)——malloc()申请内存得到指针,通过memcpy()拷贝数据到指针所指内存,指针没有改变,调用free()释放内存不会报错
- 每日练习|Day012
- JavaScript浮动广告
- 无监督神经机器翻译(UNSUPERVISED NEURAL MACHINE TRANSLATION)学习笔记
- 方法重载参数为null时处理方案
- Node.js学习(五):认识模板