MyBatis 中 like的使用

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}),‘%‘)  
时间: 2024-08-14 01:28:49

MyBatis 中 like的使用的相关文章

2017年9月3日 Spring及Mybatis中连接数据库的不同方式

连接数据库用spring和mybatis中使用的方法可以不同,mybaits可以不用写数据库的配置文件 Spring的连接方法 <!-- 读取属性文件(.properties)的内容 --> <!-- location:指定要读取的属性文件的位置及文件名. 注: classpath:表示依据类路径去查找 容器依据路径读取属性文件的内容, 并且将这些内容存放到Properties对象上 --> //数据库的登入数据文件 //文件名db.properties #db connectio

mybatis中&quot;#&quot;和&quot;$&quot;的区别

mybatis中"#"和"$"的区别 动态 sql 是 mybatis 的主要特性之一,在 mapper 中定义的参数传到 xml 中之后,在查询之前 mybatis 会对其进行动态解析.mybatis 为我们提供了两种支持动态 sql 的语法:#{} 以及 ${}. 在下面的语句中,如果 username 的值为 zhangsan,则两种方式无任何区别: select * from user where name = #{name}; select * from

mybatis中的mapper接口文件以及example类的实例函数以及详解

##Example example = new ##Example(); example.setOrderByClause("字段名 ASC"); //升序排列,desc为降序排列. example.setDistinct(false)//去除重复,boolean型,true为选择不重复的记录. Criteria criteria = new Example().createCriteria(); is null;is not null; equal to(value);not equ

MyBatis中如何通过继承SqlSessionDaoSupport来编写DAO(一)

在MyBatis中,当我们编写好访问数据库的映射器接口后,MapperScannerConfigurer就能自动成批地帮助我们根据这些接口生成DAO对象(),然后我们再使用Spring把这些DAO对象注入到业务逻辑层的对象(Service类的对象).因此,在这种情况下的DAO层,我们几乎不用编写代码,而且也没有地方编写,因为只有接口.这固然方便,不过如果我们需要在DAO层写一些代码的话,这种方式就无能为力了.此时,MyBatis-Spring提供给我们的SqlSessionDaoSupport类

MyBatis中的OGNL教程

MyBatis中的OGNL教程 有些人可能不知道MyBatis中使用了OGNL,有些人知道用到了OGNL却不知道在MyBatis中如何使用,本文就是讲如何在MyBatis中使用OGNL. 如果我们搜索OGNL相关的内容,通常的结果都是和Struts有关的,你肯定搜不到和MyBatis有关的,虽然和Struts中的用法类似但是换种方式理解起来就有难度. MyBatis常用OGNL表达式 e1 or e2 e1 and e2 e1 == e2,e1 eq e2 e1 != e2,e1 neq e2

myBatis中的注解@Param、返回值为Map、JAVA读取Excel并解析文本、Class.getResource()和ClassLoader.getResource()

myBatis中的注解@Param:http://blog.csdn.net/gao36951/article/details/44258217:  http://www.cnblogs.com/thomas12112406/p/6217211.html. myBatis返回值为Map:http://blog.csdn.net/werewr342352321df/article/details/11892755. ====================== JAVA读取Excel并解析文本:h

mybatis中xml的sql之test中文报错

在mybatis中sql,test中文报错( java.lang.NumberFormatException 这句话明确告诉了我们是数字格式异常).需加.tostring(). <if test="bookName == '毛选集'.tostring() "> and b.book_Name like #{bookName} </if>

Mybatis中的resultType和resultMap 区别

Mybatis中的resultType和resultMap 是mybatis 中返回类型一定用到的,但不会同时出现.mybatis返回类型肯定是map结构,然后根据返回类型是map还是对象类型,再转换. 在给对象设置属性的时候,两个方法肯定会调用. private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap) throws SQLException { final ResultLoaderMap lazyLoader

使用Log4jdbc-log4j2监听MyBatis中运行的SQL和Connection

引言: 在项目中使用了MyBatis,一个比较苦恼的问题是无法看到执行的SQL的具体情况,所以,就找到了Log4jdbc-log4j2.这个是一个基于jdbc层面的监听工具,可以监听对于数据库的主要操作,从而完美的查看到其中执行的操作. 1. Log4jdbc-log4j2版本选择 log4jdbc-log4j2-jdbc3.jar for JDBC 3 support in JDK 1.5 log4jdbc-log4j2-jdbc4.jar for JDBC 4 support in JDK

“mybatis 中使用foreach 传

为了帮助网友解决“mybatis 中使用foreach 传”相关的问题,中国学网通过互联网对“mybatis 中使用foreach 传”相关的解决方案进行了整理,用户详细问题包括:mybatismapsql <update id="updateallByEntity" parameterType="java.util.List"> update T_WEEKDAY <foreach item="item" index="