• mybatis04


    MyBatis大致工作流程

    SQL语句的执行会涉及多个组件,比较重要的有Executor、StatementHandler、ParameterHandler和
    ResultSetHandler。其中Executor主要负责维护一二级缓存和事务管理,将数据库相关操作委托给
    StatementHandler完成。首先StatementHandler通过ParameterHandler完成SQL语句的参数绑定,
    完成后通过Statement对象执行SQL语句,并获取返回结果集ResultSet。最后通过ResultHandler完成
    结果集到对象的映射,从而实现返回对象集合

    MyBatis工作原理

    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 ()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    在这里插入图片描述
    在这里插入图片描述

    • SqlSession作为MyBatis工作的主要顶层API,表示和数据库交互的会话,完成必要数据库增删改查功能
    • Executor:MyBatis执行器,是MyBatis调度的核心,负责SQL语句的生成和查询缓存的维护
    • StatementHandler :封装了JDBC Statement操作,负责对JDBC statement 的操作,如设置参数、将Statement结果集转换成List集合
    • ParameterHandler:负责对用户传递的参数转换成JDBC Statement 所需要的参数
    • ResultSetHandler:负责将JDBC返回的ResultSet结果集对象转换成List类型的集合
    • TypeHandler:负责java数据类型和jdbc数据类型之间的映射和转换
    • MappedStatement:MappedStatement维护了一条 节点的封装
    • SqlSource:负责根据用户传递的parameterObject,动态地生成SQL语句,将信息封装到BoundSql对象中,并返回
    • BoundSql:表示动态生成的SQL语句以及相应的参数信息
    • Configuration:MyBatis所有的配置信息都维持在Configuration对象之中。

    MyBatis框架设计

    在这里插入图片描述

    接口层

    接口层负责和数据库交互的方式
    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接口,而这个接口中声明的方法和跟
    节点中的 节点项对应,即 节点的id值为Mapper接口中的方法名称,parameterType值表示
    Mapper对应方法的入参类型,而resultMap值则对应了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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55

    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    修改映射元文件

    
    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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93

    修改对应的映射接口

    public interface UserMapper {
    int deleteByPrimaryKey(Long id);
    int insertSelective(User record);
    User selectByPrimaryKey(Long id);
    int updateByPrimaryKeySelective(User record);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    泛型通用接口的引入

    在具体的应用中,针对不同的实体基本操作是一致的,所以可以使用带有泛型的通用接口进行定义

    //这里的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);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    具体类型的映射接口,除非有特殊的方法,否则具体接口中没有方法定义

    public interface UserMapper extends SqlMapper<User,Long>{
    }
    
    • 1
    • 2

    Example样例条件

    一般不推荐使用反向映射生成进行查询条件封装的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);
    }
    }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 会导致类爆炸问题,一个实体对应一个Example类
    • 使用Example封装查询条件过于麻烦,所以不如依赖于动态sql
    • 如果查询条件比较麻烦,可以考虑使用Map参数
  • 相关阅读:
    【过程记录】Mars3D加载3DTiles三维模型
    【论文阅读】AID(ICCV‘23)
    [附源码]SSM计算机毕业设计小说网站的设计与实现1JAVA
    4.TCP UDP简单介绍
    2022 全栈开发报告:Python “火”得实至名归、前端框架依旧是“三巨头”
    基于springboot+mybatis+thymeleaf+redis+html实现的农村在线交易平台项目(含支付模块)
    超声波探伤仪是做什么用的?
    Python:线性查找法
    记一次神奇的 pipe 错误
    MFC Windows 程序设计[241]之创建多维视图效果(附源码)
  • 原文地址:https://blog.csdn.net/weixin_44251806/article/details/128207488