//Mybatis where 查询
//mapper的接口如下
public List<SysRole> findPageList(@Param("role") SysRole sysRole,
@Param("start") Integer start,
@Param("length") Integer length);
//xml配置
<resultMap id="BaseResultMap" type="sysRole">
//properties
</resultMap>
<select id="findPageList" resultMap="BaseResultMap">
SELECT * FROM sys_role
<where>
<if test="#{role.name} != null ">
name like CONCAT('%',#{role.name},'%')
</if>
<if test="#{role.delFlag} != null ">
AND del_flag = #{role.delFlag}
</if>
</where>
order by id limit #{start},#{length}
</select>
执行查询当name为空的时候,if判断还是会进去执行,网上各种搜发现很多都是这样写,
问题解决的是#{role.name}!=null,#{role.delFlag!=null} 修改为 role.name!=null,role.delFlag!=null
原来在if里不需要写#{}