Mybatis学习笔记-动态SQL与模糊查询
来源:互联网 发布:淘宝的君羊令页 编辑:程序博客网 时间:2024/04/30 18:32
需求:实现多条件查询用户(姓名模糊匹配, 年龄在指定的最小值到最大值之间)
User.java实体类
public class User {private int id;private String name;private int age;//...}
ConditionUser.java
public class ConditionUser {private String name;private int minAge;private int maxAge;//...}
<!-- 实现多条件查询用户(姓名模糊匹配, 年龄在指定的最小值到最大值之间)类似jstl表达式 --><select id="getUser" parameterType="com.mybatis.test05.ConditionUser" resultType="com.mybatis.test05.User">select * from d_user where <if test='name != "%null%"'> name like #{name} and </if>age between #{minAge} and #{maxAge}</select>
测试
SqlSessionFactory factory = MybatisUtil.getFactory();SqlSession session = factory.openSession();String statement = "com.mybatis.test05.userMapper.getUser";String name = "o";name = null;ConditionUser parameter = new ConditionUser("%"+name+"%", 13, 18);List<User> list = session.selectList(statement, parameter);System.out.println(list);session.close();
MyBatis中可用的动态SQL标签
if
choose (when otherwise)
trim (where set)
foreach
本文出自 “优赛工作室” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1559302
0 0
- Mybatis学习笔记-动态SQL与模糊查询
- Mybatis学习笔记-动态SQL和模糊查询
- Mybatis学习总结之动态SQL与模糊查询
- Mybatis学习总结之动态SQL与模糊查询
- 【Mybatis学习总结六】动态SQL与模糊查询
- Mybatis学习----模糊查询和动态sql
- MyBatis-动态sql与模糊查询 -07
- mybatis 动态SQL与模糊查询
- Mybatis动态SQL与模糊查询
- mybatis的动态SQL与模糊查询
- myBatis学习笔记(6)——动态SQL & 模糊查询
- MyBatis笔记(九)——动态SQL与模糊查询
- MyBatis动态查询 模糊查询实例sql
- 动态SQL与模糊查询
- 模糊查询与动态sql
- 动态SQL与模糊查询
- Mybatis 1.动态sql 2.模糊查询
- 03. mybatis 动态sql && 模糊查询
- Mybatis学习笔记-入门
- Mybatis学习笔记-CURD(基于配置文件的方式)
- Mybatis学习笔记-CURD(基于注解的方式)
- Mybatis学习笔记-一对一关联
- Mybatis学习笔记-一对多关联
- Mybatis学习笔记-动态SQL与模糊查询
- Mybatis学习笔记-调用存储过程
- Mybatis学习笔记-一级缓存与二级缓存
- HDU 2509 Be the Winner (Nim博弈)
- Mybatis学习笔记-Mybatis与Spring的整合
- Ajax学习笔记-入门笔记
- Ajax学习笔记-Ajax数据格式
- Ajax学习笔记-JQuery中的Ajax
- Ajax学习笔记-验证用户名是否可用