您的位置:首页 > 其它

MyBatis的Where条件查询

2016-03-24 00:00 274 查看
//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里不需要写#{}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: