问题:mybatis下mapping文件sql写的没问题,但是却查询无效果,比如根据多条模糊查询,前两条都可以,却第三条不可以等常见问题。
解决措施:检查-参数顺序,参数类别,返回结果类型
例子:
1.xml文件(模糊查询)
<select id="count" resultType="int">
SELECT count(*) AS total FROM t_user
<where>
<if test="e!= null and e!= ''" >
e_name LIKE CONCAT(CONCAT('%', #{e,jdbcType=VARCHAR}), '%')
</if>
<if test="t!= null and t!= ''" >
and t_type=#{t,jdbcType=VARCHAR}
</if>
<if test="p!= null and p!= ''" >
and p_name=#{p,jdbcType=INTEGER}
</if>
</where>
</select>
2.mapper层
int count(@Param("e") String e,@Param("t") Integer t,@Param("p") String p);
3.service层
public List<User> searchUsers(String e,Integert,String p) {
int i=userMapper.countshowpage(e, t,p);
return userMapper.searchUsers(e);
}