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('%','username','%')---mysql数据库
where username LIKE CONCAT('%',CONCAT(#{name},'%')) ---oracle

mybatis 模糊查询 like的更多相关文章

  1. Ibatis/Mybatis模糊查询

    Ibatis/Mybatis模糊查询 根据网络内容整理 Ibatis中 使用$代替#.此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险. Sql代码 select * from ...

  2. MyBatis模糊查询相关

    Mybatis模糊查询的实现不难,如下实例:在UserMapper.xml中根据用户名模糊查询用户: <!-- 模糊查询用户 --> <select id="findSom ...

  3. Mybatis 模糊查询 中文问题

    IDE编码:GBK ,换成UTF-8也不行! @Testpublic void testSearchStudents() {logger.info("查询学生(带条件)");Map ...

  4. MyBatis模糊查询不报错但查不出数据的一种解决方案

    今天在用MyBatis写一个模糊查询的时候,程序没有报错,但查不出来数据,随即做了一个测试,部分代码如下: @Test public void findByNameTest() throws IOEx ...

  5. MyBatis——模糊查询

    在mybatis中可以使用三种模糊查询的方式: <!-- 模糊查询 --> <select id="selectListByTitle" parameterTyp ...

  6. mybatis模糊查询防止SQL注入

    SQL注入,大家都不陌生,是一种常见的攻击方式.攻击者在界面的表单信息或URL上输入一些奇怪的SQL片段(例如“or ‘1’=’1’”这样的语句),有可能入侵参数检验不足的应用程序.所以,在我们的应用 ...

  7. Mybatis 模糊查询 like【笔记】Could not set parameters for mapping

    当使用mybatis 做模糊查询时如果这样写 会报 Could not set parameters for mapping: ParameterMapping{property='keywords' ...

  8. MyBatis 模糊查询的 4 种实现方式

    引言 MyBatis 有 4 种方式可以实现模糊查询. 员工信息表 ( tb_employee ) 如下: id name sex email birthday address 001 张一凡 男 z ...

  9. Mybatis模糊查询结果为空的解决方案

    写在前面 Mybatis使用模糊查询,查询结果为空的解决方案,我的代码是 select * from sp_user where 1=1 <if test="username!=nul ...

  10. mybatis模糊查询

    今天遇到一个模糊查询的问题,需求是:根据传入的时间查询当天的所有数据,解决办法是使用$或者contact,具体sql模拟如下: select * from table_name where creat ...

随机推荐

  1. 【C51】74HC573芯片

    74HC573是一个8位3态带锁存高速的逻辑芯片.下面介绍使用. 参数(仅供参考) Vcc   2~6V I in    +-20mA I out  +- 35mA 引脚图和引脚作用          ...

  2. C++ Primer Pluse_7_课后题

    #include <iostream> using namespace std; double Sum2(double x, double y) { double sum = 0; if ...

  3. 当html标签不被识别时(不解析)不妨试试htmlspecialchars_decode();试试

  4. tomcat的maxThreads、acceptCount(最大线程数、最大排队数)

    转载:http://blog.sina.com.cn/s/blog_605f5b4f01012ljj.html tomcat 的Connector配置如下 <Connector port=&qu ...

  5. 谈谈Linux下动态库查找路径的问题 ldconfig LD_LIBRARY_PATH PKG_CONFIG_PATH

    谈谈Linux下动态库查找路径的问题 ldconfig LD_LIBRARY_PATH  PKG_CONFIG_PATH 转载自:http://blog.chinaunix.net/xmlrpc.ph ...

  6. java 删除目录、 文件

    示例 import java.io.File; public class fileTest { public static void main(String []args){ String strVe ...

  7. RDIFramework.NET 中多表关联查询分页实例

    RDIFramework.NET 中多表关联查询分页实例 RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,给用户和开发者最佳的.Net框架部署方案.该框架以SOA范式作为 ...

  8. @Override的作用

    @Override是伪代码,表示重写(不写也可以,但是有些IDE会报warning),不过写上有如下好处: 1.可以当注释用,方便阅读:2.编译器可以给你验证@Override下面的方法名是否是你父类 ...

  9. AngularJS基础概要整理(下)

    五.AngularJS Scope(作用域) Scope(作用域)是应用在HTML(视图)和JavaScript(控制器)之间的纽带. Scope是一个对象,有可用的方法和属性. Scope可应用在视 ...

  10. 获取QQ企业邮箱通讯录PY脚本

    ':             root_department = department     regexp = r'{uin:"(\S*?)",pid:"(\S*?)& ...