本文主要是介绍mybatis if test 之 0当做参数传入出问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先前端传入了参数
if(StringUtils.isNotBlank(status)){requestParam.setProperty("status", Integer.parseInt(status));}
List<SuperPojo> applicationList = groupDao.getApplicationListByReviewStatusAndMember(requestParam);
mapper的sql文为
<select id="getApplicationListByReviewStatusAndMemberCount" parameterType="com.financial.core.pojo.SuperPojo"resultType="Integer" flushCache="true">SELECTcount(1)FROMreview_status rsLEFT JOIN member_info mi ON mi.member_id = rs.member_idLEFT JOIN member m ON rs.member_id = m.member_id<where><if test="name!=null and name!=''">AND mi.name like CONCAT('%',#{name},'%')</if><if test="telephone!=null and telephone!=''">AND mi.telephone = #{telephone}</if><if test="status!=null and status!=''">AND rs.status = #{status}</if><if test="applicationTimeStart!=null and applicationTimeEnd!=null">and rs.update_time >= #{applicationTimeStart} and rs.update_time <DATE_ADD(#{applicationTimeEnd},INTERVAL 1 DAY)</if></where>ORDER BY rs.update_time ASC</select>
解决方法:
mybatis的参数传入为0的时候会把0当做空处理掉
改成如下情况即可
<select id="getApplicationListByReviewStatusAndMemberCount" parameterType="com.financial.core.pojo.SuperPojo"resultType="Integer" flushCache="true">SELECTcount(1)FROMreview_status rsLEFT JOIN member_info mi ON mi.member_id = rs.member_idLEFT JOIN member m ON rs.member_id = m.member_id<where><if test="name!=null and name!=''">AND mi.name like CONCAT('%',#{name},'%')</if><if test="telephone!=null and telephone!=''">AND mi.telephone = #{telephone}</if><if test="status!=null and status!='' or 0 == status">AND rs.status = #{status}</if><if test="applicationTimeStart!=null and applicationTimeEnd!=null">and rs.update_time >= #{applicationTimeStart} and rs.update_time <DATE_ADD(#{applicationTimeEnd},INTERVAL 1 DAY)</if></where>ORDER BY rs.update_time ASC</select>
这篇关于mybatis if test 之 0当做参数传入出问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!