SQL语句的执行会涉及多个组件,比较重要的有Executor、StatementHandler、ParameterHandler和
ResultSetHandler。其中Executor主要负责维护一二级缓存和事务管理,将数据库相关操作委托给
StatementHandler完成。首先StatementHandler通过ParameterHandler完成SQL语句的参数绑定,
完成后通过Statement对象执行SQL语句,并获取返回结果集ResultSet。最后通过ResultHandler完成
结果集到对象的映射,从而实现返回对象集合
1、读取MyBatis配置文件,mybatis-config.xml为全局配置文件,配置了MyBatis的运行环境等信息,
例如数据库连接信息。
2、加载映射文件:映射文件即SQL映射文件,该文件中配置了操作数据库的SQL语句,需要在MyBatis
配置文件mybatis-config.xml中加载。mybatis-config.xml文件可以加载多个映射文件,每个文件对应数据库中的一张表。
3、构造会话工厂:通过MyBatis的环境等配置信息构建会话工厂SqlSessionFactory。
4、创建会话对象:由会话工厂创建SqlSession对象,该对象中包含了执行SQL语句的所有方法,是一个既可以发送sql执行并返回结果的,也可以获取mapper的接口
5、Executor执行器:MyBatis底层定义了一个Executor接口来操作数据库,它将根据SqlSession传递的参数动态地生成需要执行的SQL语句,同时负责查询缓存的维护。
6、MappedStatement对象:在Executor接口的执行方法中有一个MappedStatement类型的参数,该
参数是对映射信息的封装,用于存储要映射的SQL语句的 id、参数等信息。
7、输入参数映射:输入参数类型可以是Map、List等集合类型,也可以是基本数据类型和POJO类型。
输入参数映射过程类似于JDBC对preparedStatement对象设置参数的过程。
8、输出结果映射:输出结果类型可以是Map、 List等集合类型,也可以是基本数据类型和POJO类型。
输出结果映射过程类似于JDBC对结果集的解析过程。
final Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
final SqlSessionFactory sessionFactory = new
SqlSessionFactoryBuilder().build(reader);
final SqlSession sqlSession = sessionFactory.openSession();//Connection
// final Connection connection = sqlSession.getConnection();
// sqlSession.insert("com.yan.dao.UserMapper.insertUser",user) / delete() /
update / selectList ()



接口层负责和数据库交互的方式
MyBatis和数据库的交互有两种方式:
1、使用传统的MyBatis提供的API。
sqlSession.insert(“com.yan.dao.UserMapper.insertUser”,user)
2、使用Mapper接口 UserMapper mapper=sqlSession.getMapper(UserMapper.class); int
res=mapper.insertUser(user);
1、使用传统的MyBatis提供的API
sqlSession.insert(“com.yan.dao.UserMapper.insert”,user)
这是传统的传递Statement Id 【com.yan.dao.UserMapper.insert】和查询参数【user】给SqlSession对象,使用SqlSession对象完成和数据库的交互;MyBatis提供了非常方便和简单的API,供用户实现对数据库的增删改查数据操作以及对数据库连接信息和MyBatis自身配置信息的维护操作。
创建一个和数据库打交道的SqlSession对象,然后根据Statement Id和参数来操作数据库,这种方式固然很简单和实用,但是它不符合面向对象语言的概念和面向接口编程的编程习惯。由于面向接口的编程是面向对象的大趋势,MyBatis为了适应这一趋势,增加了第二种使用MyBatis支持接口调用方式。
2、使用Mapper接口
UserMapper mapper=sqlSession.getMapper(UserMapper.class); int
res=mapper.insert(user);
MyBatis将配置文件中的每一个 节点抽象为一个Mapper接口,而这个接口中声明的方法和跟
节点中的
根据MyBatis的配置规范配置好后,通过SqlSession.getMapper(XXXMapper.class)方法会根据相应的接口声明的方法信息,通过动态代理机制生成一个Mapper实例,使用Mapper接口的某一个方法时会根据这个方法的方法名和参数类型,确定Statement Id,底层还是通过SqlSession.select(“statementId”,parameterObject);或者
SqlSession.update(“statementId”,parameterObject);等来实现对数据库的操作,MyBatis引用Mapper
接口这种调用方式,纯粹是为了满足面向接口编程的需要。面向接口的编程使得用户在接口上可以使用
注解来配置SQL语句,这样就可以脱离XML配置文件,实现0配置。
a. 通过传入参数构建动态SQL语句;
b. SQL语句的执行以及封装查询结果集成 List
1、参数映射和动态SQL语句生成。动态语句是通过传入的参数值,使用Ognl来动态地构造SQL语句,使
得MyBatis有很强的灵活性和扩展性。参数映射指的是对于java 数据类型和jdbc数据类型之间的转换:
有两个过程。查询阶段是将java类型的数据,转换成jdbc类型的数据,通过preparedStatement.setXXX()来设值;另一个就是对resultset查询结果集的jdbcType 数据转换成java数据类型。
2、SQL语句的执行以及封装查询结果集成 List 。动态SQL语句生成之后,MyBatis将执行SQL语句,并将可能返回的结果集转换成 List 列表。MyBatis在对结果集的处理中,支持结果集关系一对多和多对一的转换,并且有两种支持方式,一种为嵌套查询语句的查询,还有一种是嵌套结果集的查询。
1、事务管理机制。
2、连接池管理机制。由于创建一个数据库连接所占用的资源比较大,对于数据吞吐量大和访问量非常大
的应用而言,连接池的设计就显得非常重要。
3、缓存机制。为了提高数据利用率和减小服务器和数据库的压力,MyBatis会对于一些查询提供会话级
别的数据缓存,会将对某一次查询,放置到SqlSession中,在允许的时间间隔内,对于完全相同的查询,MyBatis会直接将缓存结果返回给用户,而不用再到数据库中查找。
4、SQL语句的配置方式。传统的MyBatis配置SQL语句方式就是使用XML文件进行配置的,但是这种方
式不能很好地支持面向接口编程的理念,为了支持面向接口的编程,MyBatis引入了Mapper接口的概
念,面向接口的引入,对使用注解来配置SQL语句成为可能,用户只需要在接口上添加必要的注解即
可,不用再去配置XML文件了,但是,目前的MyBatis只是对注解配置SQL语句提供了有限的支持,某些高级功能还是要依赖XML配置文件配置SQL语句。
引导层是配置和启动MyBatis配置信息的方式。MyBatis提供两种方式来引导MyBatis:基于XML配置文件的方式和基于Java API的方式
MyBatis是目前非常流行的持久层框架,其逆向工程更是大大缩减了开发时间。所谓mybatis逆向工程,
就是根据设计好的数据表,自动生成pojo实体【实体类】、mapper接口以及mapper.xml映射元文件,
可使用mybatis-generator的maven插件。
1、设计创建表
create table if not exists t_users(
id bigint primary key auto_increment,
username varchar(20) not null unique,
password varchar(20) not null,
birth date,
sex boolean default 1,
salary numeric(8,2)
)engine=innodb default charset utf8;
2、修改pom.xml文件引入maven插件
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-maven-pluginartifactId>
<version>1.4.0version>
<configuration>
<configurationFile>src/main/resources/mybatisgenerator/mybatis-generator-cfg.xmlconfigurationFile>
<verbose>trueverbose>
<overwrite>trueoverwrite>
configuration>
<executions>
executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-coreartifactId>
<version>1.4.0version>
dependency>
dependencies>
plugin>
plugins>
build>
3、添加反向映射配置文件mybatis-generator-cfg.xml
DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="test" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true" />
<property name="suppressAllComments" value="false" />
commentGenerator>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost/test?
serverTimezone=UTC"
userId="root"
password="123456">
jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
javaTypeResolver>
<javaModelGenerator targetPackage="com.yan.entity"
targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
javaModelGenerator>
<sqlMapGenerator targetPackage="mapper"
targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.yan.dao"
targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
javaClientGenerator>
<table tableName="t_users" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">table>
context>
generatorConfiguration>
4、运行maven命令: mybatis-generator:generate

5、针对反向映射生成的内容进行修改
实体类
@Data
public class User implements Serializable {
private Long id;
private String username;
private String password;
private Date birth;
private Boolean sex;
private Double salary;
}
修改映射元文件
DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yan.dao.UserMapper">
<resultMap id="BaseResultMap" type="com.yan.entity.User">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="username" jdbcType="VARCHAR" property="username" />
<result column="password" jdbcType="VARCHAR" property="password" />
<result column="birth" jdbcType="DATE" property="birth" />
<result column="sex" jdbcType="BOOLEAN" property="sex" />
<result column="salary" jdbcType="DECIMAL" property="salary" />
resultMap>
<sql id="Base_Column_List">
id, username, password, birth, sex, salary
sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_users
where id = #{id,jdbcType=BIGINT}
select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from t_users
where id = #{id,jdbcType=BIGINT}
delete>
<insert id="insertSelective" parameterType="com.yan.entity.User"
useGeneratedKeys="true" keyProperty="id">
insert into t_users
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
if>
<if test="username != null">
username,
if>
<if test="password != null">
password,
if>
<if test="birth != null">
birth,
if>
<if test="sex != null">
sex,
if>
<if test="salary != null">
salary,
if>
trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
if>
<if test="username != null">
#{username,jdbcType=VARCHAR},
if>
<if test="password != null">
#{password,jdbcType=VARCHAR},
if>
<if test="birth != null">
#{birth,jdbcType=DATE},
if>
<if test="sex != null">
#{sex,jdbcType=BOOLEAN},
if>
<if test="salary != null">
#{salary,jdbcType=DECIMAL},
if>
trim>
insert>
<update id="updateByPrimaryKeySelective"
parameterType="com.yan.entity.User">
update t_users
<set>
<if test="username != null">
username = #{username,jdbcType=VARCHAR},
if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
if>
<if test="birth != null">
birth = #{birth,jdbcType=DATE},
if>
<if test="sex != null">
sex = #{sex,jdbcType=BOOLEAN},
if>
<if test="salary != null">
salary = #{salary,jdbcType=DECIMAL},
if>
set>
where id = #{id,jdbcType=BIGINT}
update>
mapper>
修改对应的映射接口
public interface UserMapper {
int deleteByPrimaryKey(Long id);
int insertSelective(User record);
User selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(User record);
}
在具体的应用中,针对不同的实体基本操作是一致的,所以可以使用带有泛型的通用接口进行定义
//这里的T就是值bean,实体类; ID是标识属性,或者主键类型
public interface SqlMapper<T extends Serializable,ID extends Serializable> {
int deleteByPrimaryKey(ID id);
int insertSelective(T record);
T selectByPrimaryKey(ID id);
int updateByPrimaryKeySelective(T record);
}
具体类型的映射接口,除非有特殊的方法,否则具体接口中没有方法定义
public interface UserMapper extends SqlMapper<User,Long>{
}
一般不推荐使用反向映射生成进行查询条件封装的Example,但是一些简单操作中可以考虑使用
Example
public class UserExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public UserExample() {
oredCriteria = new ArrayList<>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be
null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String
property) {
if (value == null) {
throw new RuntimeException("Value for " + property + "
cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object
value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property
+ " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
protected void addCriterionForJDBCDate(String condition, Date
value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + "
cannot be null");
}
addCriterion(condition, new java.sql.Date(value.getTime()),
property);
}
protected void addCriterionForJDBCDate(String condition, List<Date>
values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property + "
cannot be null or empty");
}
List<java.sql.Date> dateList = new ArrayList<>();
Iterator<Date> iter = values.iterator();
while (iter.hasNext()) {
dateList.add(new java.sql.Date(iter.next().getTime()));
}
addCriterion(condition, dateList, property);
}
protected void addCriterionForJDBCDate(String condition, Date
value1, Date value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property
+ " cannot be null");
}
addCriterion(condition, new java.sql.Date(value1.getTime()),
new java.sql.Date(value2.getTime()), property);
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(Long value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(Long value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(Long value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(Long value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(Long value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(Long value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<Long> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Long> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(Long value1, Long value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(Long value1, Long value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andUsernameIsNull() {
addCriterion("username is null");
return (Criteria) this;
}
public Criteria andUsernameIsNotNull() {
addCriterion("username is not null");
return (Criteria) this;
}
public Criteria andUsernameEqualTo(String value) {
addCriterion("username =", value, "username");
return (Criteria) this;
}
public Criteria andUsernameNotEqualTo(String value) {
addCriterion("username <>", value, "username");
return (Criteria) this;
}
public Criteria andUsernameGreaterThan(String value) {
addCriterion("username >", value, "username");
return (Criteria) this;
}
public Criteria andUsernameGreaterThanOrEqualTo(String value) {
addCriterion("username >=", value, "username");
return (Criteria) this;
}
public Criteria andUsernameLessThan(String value) {
addCriterion("username <", value, "username");
return (Criteria) this;
}
public Criteria andUsernameLessThanOrEqualTo(String value) {
addCriterion("username <=", value, "username");
return (Criteria) this;
}
public Criteria andUsernameLike(String value) {
addCriterion("username like", value, "username");
return (Criteria) this;
}
public Criteria andUsernameNotLike(String value) {
addCriterion("username not like", value, "username");
return (Criteria) this;
}
public Criteria andUsernameIn(List<String> values) {
addCriterion("username in", values, "username");
return (Criteria) this;
}
public Criteria andUsernameNotIn(List<String> values) {
addCriterion("username not in", values, "username");
return (Criteria) this;
}
public Criteria andUsernameBetween(String value1, String value2) {
addCriterion("username between", value1, value2, "username");
return (Criteria) this;
}
public Criteria andUsernameNotBetween(String value1, String value2)
{
addCriterion("username not between", value1, value2,
"username");
return (Criteria) this;
}
public Criteria andPasswordIsNull() {
addCriterion("password is null");
return (Criteria) this;
}
public Criteria andPasswordIsNotNull() {
addCriterion("password is not null");
return (Criteria) this;
}
public Criteria andPasswordEqualTo(String value) {
addCriterion("password =", value, "password");
return (Criteria) this;
}
public Criteria andPasswordNotEqualTo(String value) {
addCriterion("password <>", value, "password");
return (Criteria) this;
}
public Criteria andPasswordGreaterThan(String value) {
addCriterion("password >", value, "password");
return (Criteria) this;
}
public Criteria andPasswordGreaterThanOrEqualTo(String value) {
addCriterion("password >=", value, "password");
return (Criteria) this;
}
public Criteria andPasswordLessThan(String value) {
addCriterion("password <", value, "password");
return (Criteria) this;
}
public Criteria andPasswordLessThanOrEqualTo(String value) {
addCriterion("password <=", value, "password");
return (Criteria) this;
}
public Criteria andPasswordLike(String value) {
addCriterion("password like", value, "password");
return (Criteria) this;
}
public Criteria andPasswordNotLike(String value) {
addCriterion("password not like", value, "password");
return (Criteria) this;
}
public Criteria andPasswordIn(List<String> values) {
addCriterion("password in", values, "password");
return (Criteria) this;
}
public Criteria andPasswordNotIn(List<String> values) {
addCriterion("password not in", values, "password");
return (Criteria) this;
}
public Criteria andPasswordBetween(String value1, String value2) {
addCriterion("password between", value1, value2, "password");
return (Criteria) this;
}
public Criteria andPasswordNotBetween(String value1, String value2)
{
addCriterion("password not between", value1, value2,
"password");
return (Criteria) this;
}
public Criteria andBirthIsNull() {
addCriterion("birth is null");
return (Criteria) this;
}
public Criteria andBirthIsNotNull() {
addCriterion("birth is not null");
return (Criteria) this;
}
public Criteria andBirthEqualTo(Date value) {
addCriterionForJDBCDate("birth =", value, "birth");
return (Criteria) this;
}
public Criteria andBirthNotEqualTo(Date value) {
addCriterionForJDBCDate("birth <>", value, "birth");
return (Criteria) this;
}
public Criteria andBirthGreaterThan(Date value) {
addCriterionForJDBCDate("birth >", value, "birth");
return (Criteria) this;
}
public Criteria andBirthGreaterThanOrEqualTo(Date value) {
addCriterionForJDBCDate("birth >=", value, "birth");
return (Criteria) this;
}
public Criteria andBirthLessThan(Date value) {
addCriterionForJDBCDate("birth <", value, "birth");
return (Criteria) this;
}
public Criteria andBirthLessThanOrEqualTo(Date value) {
addCriterionForJDBCDate("birth <=", value, "birth");
return (Criteria) this;
}
public Criteria andBirthIn(List<Date> values) {
addCriterionForJDBCDate("birth in", values, "birth");
return (Criteria) this;
}
public Criteria andBirthNotIn(List<Date> values) {
addCriterionForJDBCDate("birth not in", values, "birth");
return (Criteria) this;
}
public Criteria andBirthBetween(Date value1, Date value2) {
addCriterionForJDBCDate("birth between", value1, value2,
"birth");
return (Criteria) this;
}
public Criteria andBirthNotBetween(Date value1, Date value2) {
addCriterionForJDBCDate("birth not between", value1, value2,
"birth");
return (Criteria) this;
}
public Criteria andSexIsNull() {
addCriterion("sex is null");
return (Criteria) this;
}
public Criteria andSexIsNotNull() {
addCriterion("sex is not null");
return (Criteria) this;
}
public Criteria andSexEqualTo(Boolean value) {
addCriterion("sex =", value, "sex");
return (Criteria) this;
}
public Criteria andSexNotEqualTo(Boolean value) {
addCriterion("sex <>", value, "sex");
return (Criteria) this;
}
public Criteria andSexGreaterThan(Boolean value) {
addCriterion("sex >", value, "sex");
return (Criteria) this;
}
public Criteria andSexGreaterThanOrEqualTo(Boolean value) {
addCriterion("sex >=", value, "sex");
return (Criteria) this;
}
public Criteria andSexLessThan(Boolean value) {
addCriterion("sex <", value, "sex");
return (Criteria) this;
}
public Criteria andSexLessThanOrEqualTo(Boolean value) {
addCriterion("sex <=", value, "sex");
return (Criteria) this;
}
public Criteria andSexIn(List<Boolean> values) {
addCriterion("sex in", values, "sex");
return (Criteria) this;
}
public Criteria andSexNotIn(List<Boolean> values) {
addCriterion("sex not in", values, "sex");
return (Criteria) this;
}
public Criteria andSexBetween(Boolean value1, Boolean value2) {
addCriterion("sex between", value1, value2, "sex");
return (Criteria) this;
}
public Criteria andSexNotBetween(Boolean value1, Boolean value2) {
addCriterion("sex not between", value1, value2, "sex");
return (Criteria) this;
}
public Criteria andSalaryIsNull() {
addCriterion("salary is null");
return (Criteria) this;
}
public Criteria andSalaryIsNotNull() {
addCriterion("salary is not null");
return (Criteria) this;
}
public Criteria andSalaryEqualTo(BigDecimal value) {
addCriterion("salary =", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryNotEqualTo(BigDecimal value) {
addCriterion("salary <>", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryGreaterThan(BigDecimal value) {
addCriterion("salary >", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryGreaterThanOrEqualTo(BigDecimal value) {
addCriterion("salary >=", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryLessThan(BigDecimal value) {
addCriterion("salary <", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryLessThanOrEqualTo(BigDecimal value) {
addCriterion("salary <=", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryIn(List<BigDecimal> values) {
addCriterion("salary in", values, "salary");
return (Criteria) this;
}
public Criteria andSalaryNotIn(List<BigDecimal> values) {
addCriterion("salary not in", values, "salary");
return (Criteria) this;
}
public Criteria andSalaryBetween(BigDecimal value1, BigDecimal
value2) {
addCriterion("salary between", value1, value2, "salary");
return (Criteria) this;
}
public Criteria andSalaryNotBetween(BigDecimal value1, BigDecimal
value2) {
addCriterion("salary not between", value1, value2, "salary");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String
typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object
secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object
secondValue) {
this(condition, value, secondValue, null);
}
}
}