mybatis字符串模糊匹配
2016-04-08 17:39
375 查看
1. 参数中直接加入%%,注意不需要加两个单引号,加了就会出错,因为系统会自动为字符串类型加上两个单引号
2. bind标签
3. concat函数
<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 cancat('%',#{username},'%') 这三种方式哪个好呢?concat必然会先耗时间去执行函数费数据库的事,bind费mybatis的事,第一种方式费java代码的事。方法一简单明了直观,便于用代码控制,最好。
相关文章推荐
- android中关于文件解码时出现乱码的相关分析
- 数据结构-堆
- 数据库NOT EXISTS的理解
- angular modalInstance模态框
- Android React-Native系列之<二>零基础学习React-Native控件之View
- 推荐cms
- JavaPersistenceWithHibernate第二版笔记-第七章-001Mapping a set(@ElementCollection、@CollectionTable、@JoinColumn、)
- mybatis字符串模糊匹配
- windows下创建并使用静态链接库(.lib)
- Android上传图片之调用系统拍照和从相册选择图片
- 第五届计算机职业资格认证考试CCF (第三题)
- Flex布局实现圣杯布局,左右两列固定、中间列自适应的三列式布局
- HBase高级配置跟调整(1)
- Struts2学习笔记
- 100个高质量Java开发者博客
- 汉堡
- 机器学习 -- 基本数学概念总结
- 学习笔记之曾经迷惑于输入输出
- 算法 —— URL短地址压缩算法
- 自己拿傅里叶变换公式实现2维傅里叶变换