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里不需要写#{}
相关文章推荐
- Mybatis自动插入自增id
- MyBatis批量操作
- jstree ajax请求加在数据
- 项目中遇到通过使用路由策略实现主从数据库访问数据不同步的问题
- redis事务
- redis 的setnx命令
- Hadoop单机版和伪分布式部署
- css遇到的垂直水平居中(个人学习笔记)
- ios选项卡按钮
- Linux kudzu !!!上天了
- tq2440 adc+中断 驱动
- 我的 IP 地址(View IP address)
- Patchwork & Quilting(拼布和绗缝)
- Wire(聊天工具)
- Merge PDF - Split PDF(PDF合成)
- 享听音乐播放器(Enjoy listening to music player)
- 使用NSTimer出现的问题
- 2016淘宝首页今日改版,细说淘宝首页设计变化史
- topdownCar 例子
- 推荐一些C#相关的网站、资源和书籍