mysql中的模糊查询
来源:互联网 发布:无线路由器mac绑定 编辑:程序博客网 时间:2024/06/05 04:35
原文链接:http://www.cnblogs.com/cyttina/p/3894428.html
http://blog.sina.com.cn/s/blog_667bef380101f2da.html
1. 参数中直接加入%%
param.setUsername("%CD%");
param.setPassword("%11%");
<select id="selectPersons" resultType="person" parameterType="person">select id,sex,age,username,password from person where true <if test="username!=null"> AND username LIKE #{username}</if><if test="password!=null">AND password LIKE #{password}</if></select>
2. bind标签
<select id="selectPersons" resultType="person" parameterType="person"> <bind name="pattern" value="'%' + _parameter.username + '%'" /> select id,sex,age,username,password from person where username LIKE #{pattern}</select>
3. CONCAT
where username LIKE concat(concat('%',#{username}),'%')
模糊查询:
工作中用到,写三种用法吧,第四种为大小写匹配查询
1. sql中字符串拼接
2. 使用 ${...} 代替 #{...}
3. 程序中拼接
4. 大小写匹配查询
- SELECT * FROM TABLENAME WHERE UPPER(SUBSYSTEM) LIKE '%' || UPPER('jz') || '%'
- --或者是
- SELECT * FROM TABLENAME WHERE LOWER(SUBSYSTEM) LIKE '%' || LOWER('jz') || '%'
最后一个是在自己写的时候,由于关键字为空,查询不出来的情况
<select id="queryPassMember" parameterType="map" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from shop_employee_relation<where><if test="shopId != null">SHOP_ID= #{shopId}and delete_flag=1</if><if test="mobile !=null and mobile !=''">AND shopkeeper_phone LIKEconcat(concat('%',#{mobile}),'%')</if><if test="memberName !=null and memberName !=''">AND member_name LIKE concat(concat('%',#{memberName}),'%')</if></where>order by ROLE asc</select>题外话:今天下午状态突然下降,有点饿,坐等下班中。
阅读全文
0 0
- mysql中的模糊查询
- mysql中的模糊查询
- mysql中的模糊查询复习
- MySQL中的模糊查询:like
- MySQL中的模糊查询和通配符转义
- MySQL中的模糊查询和通配符转义
- mysql中的模糊查询的用法
- python中的mysql数据库like模糊查询
- mysql中的四种模糊查询
- MySQL分页查询和模糊查询中的小细节
- mysql模糊查询用法
- MYSQL模糊查询
- MySQL模糊查询语法
- MySQL模糊查询语法
- MySQL模糊查询语法
- MySQL模糊查询语法
- Mysql 模糊查询
- mysql模糊查询简介
- 一个demo学会css
- 现在才知道Java中变量声明可以放在赋值后面。。。
- 设计模式之职责链模式
- 快速、插入、冒泡排序,二分查找
- CentOS7 安装ARM Linux交叉编译环境
- mysql中的模糊查询
- 代理模式 | Proxy Pattern
- 图论小结(最小生成树)
- map函数学习
- X问题
- RecyclerView的ItemAnimator
- 搜索引擎选择: Elasticsearch与Solr
- SYN Flood攻击及防御方法
- json学习