MyBatis 模糊查询 like %
来源:互联网 发布:货运单打印软件 编辑:程序博客网 时间:2024/05/18 01:59
我们在配置mapper文件的时候,想做模糊查询的配置,就像这样:
<select id="getAllUserRoleDepByName" resultMap="userRoleDepList"> select u.*,r.*,d.* from user u left join user_role ur on u.user_id=ur.user_id left join role r on r.role_id=ur.role_id left join department d on <if test="user_name != null"> u.department_id = d.department_id where u.user_name like '%#{user_name}%' </if> </select>
或者这样:
<select id="getAllUserRoleDepByName" resultMap="userRoleDepList"> select u.*,r.*,d.* from user u left join user_role ur on u.user_id=ur.user_id left join role r on r.role_id=ur.role_id left join department d on <if test="user_name != null"> u.department_id = d.department_id where u.user_name like '%' + #{user_name} + '%' </if> </select>
发现都不管用,运行报错,也在网上找了一些方法都没成功,最后还是在mybatis官网中看到动态sql中的bind方法,才解决问题,方法如下:
bind中定义相关属性。
<select id="getAllUserRoleDepByName" resultMap="userRoleDepList"> <bind name="pattern" value="'%' + user_name + '%'"/> select u.*,r.*,d.* from user u left join user_role ur on u.user_id=ur.user_id left join role r on r.role_id=ur.role_id left join department d on <if test="user_name != null"> u.department_id = d.department_id where u.user_name like #{pattern} </if> </select>
0 0
- Mybatis LIKE 模糊查询
- MyBatis 模糊查询 like %
- Mybatis like 模糊查询问题
- Mybatis like 模糊查询问题
- Mybatis的like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- MyBatis的like模糊查询
- mybatis like 模糊查询问题
- Mybatis中的模糊查询(like)
- mybatis做模糊查询 like
- mybatis做like模糊查询
- Mybatis中like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- 屏幕内容显示原理
- C语言大作业
- 解决某些有到期时间的场景,不适合定时扫描表来完成处理的情况
- 算法设计Week12 LeetCode Algorithms Problem #63 Unique Paths II
- Lattice Diamond与modelsim联合仿真环境设置
- MyBatis 模糊查询 like %
- hdu_女生赛_6030递推+矩阵
- 用Metasploit破解ftp用户名和密码
- Huffman树与Huffman编码
- error: macro names must be identifiers
- sql语句中----删除表数据drop、truncate和delete的用法
- [数据结构]魔王语言解释 c语言实现
- 关于数据库的随笔
- JAVA JDBC连接 SQLServer2012