myBatis学习笔记(6)——动态SQL & 模糊查询
2015-05-12 22:35
731 查看
#动态SQL与模糊查询
这里使用到了
使用if标签,来动态增加查询的条件
查询
<select id="selectUser" parameterType="Map" resultType="User"> select * from user where 1=1 <if test="name != '%null%' "> and username like #{name} </if> <if test="money != null and money > 0"> and money <![CDATA[>]]> #{money} </if> </select>
这里使用到了
<![CDATA[>]]>表示大于号。大于号和小于号在xml文件中是比较特殊的,不能直接使用,应该
<![CDATA[value]]>来表示,可以参考spring学习笔记(3)——bean配置细节注意
使用if标签,来动态增加查询的条件
1=1是为了避免所有条件都会空时,语句错误
查询
SqlSessionFactory factory = MyBatisUtil.getFactory(); SqlSession session = factory.openSession(true); String statement = "com.bank.userMapper.selectUser"; Map<String,Object> map = new HashMap<String, Object>(); String name = "o"; map.put("name", "%"+name+"%"); map.put("money", 10); System.out.println(session.selectList(statement, map)); session.close();
相关文章推荐
- Mybatis学习笔记-动态SQL和模糊查询
- Mybatis学习总结之动态SQL与模糊查询
- 【Mybatis学习总结六】动态SQL与模糊查询
- Mybatis学习----模糊查询和动态sql
- Mybatis学习总结之动态SQL与模糊查询
- MyBatis笔记(九)——动态SQL与模糊查询
- MyBatis笔记07 - 动态SQL与模糊查询
- 03. mybatis 动态sql && 模糊查询
- Mybatis学习笔记-动态SQL与模糊查询
- mybatis学习笔记(8)-动态sql
- Mybatis动态SQL与模糊查询
- MyBatis学习笔记-注解SQL多个参数查询异常处理
- MyBatis学习笔记(五)---mybatis 动态sql语句
- MyBatis动态SQL与模糊查询
- MyBatis-动态sql与模糊查询 -07
- Mybatis学习笔记(九)【动态sql】
- MyBatis动态sql中模糊查询
- mybatis学习笔记(8)-动态sql
- mybatis学习笔记(2)--动态sql
- 利用mybatis的动态sql 进行批量模糊查询