mybatis if test 之 0当做参数传入出问题

来源:互联网 发布:知乎 中科院上海微系统 编辑:程序博客网 时间:2024/05/20 12:20

首先前端传入了参数

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">          SELECT              count(1)          FROM              review_status rs          LEFT JOIN member_info mi ON mi.member_id = rs.member_id          LEFT 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">          SELECT              count(1)          FROM              review_status rs          LEFT JOIN member_info mi ON mi.member_id = rs.member_id          LEFT 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>  




原创粉丝点击