mybatis学习(41):使用逆向工程

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: mybatis学习(41):使用逆向工程

新建一个项目,将逆向工程的生成的拷贝进来

 image.png

配置文件

log4j.properties

### \u914D\u7F6E\u6839 ###

log4j.rootLogger = debug,console ,fileAppender,dailyRollingFile,ROLLING_FILE,MAIL,DATABASE

 

### \u8BBE\u7F6E\u8F93\u51FAsql\u7684\u7EA7\u522B\uFF0C\u5176\u4E2Dlogger\u540E\u9762\u7684\u5185\u5BB9\u5168\u90E8\u4E3Ajar\u5305\u4E2D\u6240\u5305\u542B\u7684\u5305\u540D ###

log4j.logger.org.apache=dubug

log4j.logger.java.sql.Connection=dubug

log4j.logger.java.sql.Statement=dubug

log4j.logger.java.sql.PreparedStatement=dubug

log4j.logger.java.sql.ResultSet=dubug

 

### \u914D\u7F6E\u8F93\u51FA\u5230\u63A7\u5236\u53F0 ###

log4j.appender.console = org.apache.log4j.ConsoleAppender

log4j.appender.console.Target = System.out

log4j.appender.console.layout = org.apache.log4j.PatternLayout

log4j.appender.console.layout.ConversionPattern =  %d{ABSOLUTE} %5p %c{1}:%L - %m%n

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

<settings>

   <setting name="useGeneratedKeys" value="true"/>

</settings>

<typeAliases>

   <typeAlias type="com.geyao.mybatis.pojo.Blog" alias="Blog"/>

</typeAliases>

   <environments default="development">

       <environment id="development">

           <transactionManager type="JDBC" />

           <!-- 配置数据库连接信息 -->

           <dataSource type="POOLED">

               <property name="driver" value="com.mysql.cj.jdbc.Driver" />

               <property name="url" value="jdbc:mysql://localhost:3306/blog_gp1701?serverTimezone=GMT%2B8" />

               <property name="username" value="root" />

               <property name="password" value="123" />

           </dataSource>

       </environment>

   </environments>

     <mappers>

       <!-- 注册userMapper.xml文件,  

        userMapper.xml位于me.gacl.mapping这个包下,所以resource写成me/gacl/mapping/userMapper.xml-->

        <mapper resource="com/geyao/mybatis/mapper/BlogMapper.xml"/>

    </mappers>

</configuration>

com.geyao.mybatis.mapper

BlogMapper.java

package com.geyao.mybatis.mapper;

 

import com.geyao.mybatis.pojo.Blog;

import com.geyao.mybatis.pojo.BlogExample;

import java.util.List;

import org.apache.ibatis.annotations.Param;

 

public interface BlogMapper {

   int countByExample(BlogExample example);

 

   int deleteByExample(BlogExample example);

 

   int insert(Blog record);

 

   int insertSelective(Blog record);

 

   List<Blog> selectByExample(BlogExample example);

 

   int updateByExampleSelective(@Param("record") Blog record, @Param("example") BlogExample example);

 

   int updateByExample(@Param("record") Blog record, @Param("example") BlogExample example);

}

BlogMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="com.geyao.mybatis.mapper.BlogMapper" >

 <resultMap id="BaseResultMap" type="com.geyao.mybatis.pojo.Blog" >

   <result column="id" property="id" jdbcType="INTEGER" />

   <result column="title" property="title" jdbcType="VARCHAR" />

   <result column="authod_id" property="authodId" jdbcType="INTEGER" />

   <result column="state" property="state" jdbcType="VARCHAR" />

   <result column="featured" property="featured" jdbcType="TINYINT" />

   <result column="style" property="style" jdbcType="VARCHAR" />

 </resultMap>

 <sql id="Example_Where_Clause" >

   <where >

     <foreach collection="oredCriteria" item="criteria" separator="or" >

       <if test="criteria.valid" >

         <trim prefix="(" suffix=")" prefixOverrides="and" >

           <foreach collection="criteria.criteria" item="criterion" >

             <choose >

               <when test="criterion.noValue" >

                 and ${criterion.condition}

               </when>

               <when test="criterion.singleValue" >

                 and ${criterion.condition} #{criterion.value}

               </when>

               <when test="criterion.betweenValue" >

                 and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

               </when>

               <when test="criterion.listValue" >

                 and ${criterion.condition}

                 <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >

                   #{listItem}

                 </foreach>

               </when>

             </choose>

           </foreach>

         </trim>

       </if>

     </foreach>

   </where>

 </sql>

 <sql id="Update_By_Example_Where_Clause" >

   <where >

     <foreach collection="example.oredCriteria" item="criteria" separator="or" >

       <if test="criteria.valid" >

         <trim prefix="(" suffix=")" prefixOverrides="and" >

           <foreach collection="criteria.criteria" item="criterion" >

             <choose >

               <when test="criterion.noValue" >

                 and ${criterion.condition}

               </when>

               <when test="criterion.singleValue" >

                 and ${criterion.condition} #{criterion.value}

               </when>

               <when test="criterion.betweenValue" >

                 and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

               </when>

               <when test="criterion.listValue" >

                 and ${criterion.condition}

                 <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >

                   #{listItem}

                 </foreach>

               </when>

             </choose>

           </foreach>

         </trim>

       </if>

     </foreach>

   </where>

 </sql>

 <sql id="Base_Column_List" >

   id, title, authod_id, state, featured, style

 </sql>

 <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.geyao.mybatis.pojo.BlogExample" >

   select

   <if test="distinct" >

     distinct

   </if>

   <include refid="Base_Column_List" />

   from blog

   <if test="_parameter != null" >

     <include refid="Example_Where_Clause" />

   </if>

   <if test="orderByClause != null" >

     order by ${orderByClause}

   </if>

 </select>

 <delete id="deleteByExample" parameterType="com.geyao.mybatis.pojo.BlogExample" >

   delete from blog

   <if test="_parameter != null" >

     <include refid="Example_Where_Clause" />

   </if>

 </delete>

 <insert id="insert" parameterType="com.geyao.mybatis.pojo.Blog" >

   insert into blog (id, title, authod_id,  

     state, featured, style

     )

   values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{authodId,jdbcType=INTEGER},  

     #{state,jdbcType=VARCHAR}, #{featured,jdbcType=TINYINT}, #{style,jdbcType=VARCHAR}

     )

 </insert>

 <insert id="insertSelective" parameterType="com.geyao.mybatis.pojo.Blog" >

   insert into blog

   <trim prefix="(" suffix=")" suffixOverrides="," >

     <if test="id != null" >

       id,

     </if>

     <if test="title != null" >

       title,

     </if>

     <if test="authodId != null" >

       authod_id,

     </if>

     <if test="state != null" >

       state,

     </if>

     <if test="featured != null" >

       featured,

     </if>

     <if test="style != null" >

       style,

     </if>

   </trim>

   <trim prefix="values (" suffix=")" suffixOverrides="," >

     <if test="id != null" >

       #{id,jdbcType=INTEGER},

     </if>

     <if test="title != null" >

       #{title,jdbcType=VARCHAR},

     </if>

     <if test="authodId != null" >

       #{authodId,jdbcType=INTEGER},

     </if>

     <if test="state != null" >

       #{state,jdbcType=VARCHAR},

     </if>

     <if test="featured != null" >

       #{featured,jdbcType=TINYINT},

     </if>

     <if test="style != null" >

       #{style,jdbcType=VARCHAR},

     </if>

   </trim>

 </insert>

 <select id="countByExample" parameterType="com.geyao.mybatis.pojo.BlogExample" resultType="java.lang.Integer" >

   select count(*) from blog

   <if test="_parameter != null" >

     <include refid="Example_Where_Clause" />

   </if>

 </select>

 <update id="updateByExampleSelective" parameterType="map" >

   update blog

   <set >

     <if test="record.id != null" >

       id = #{record.id,jdbcType=INTEGER},

     </if>

     <if test="record.title != null" >

       title = #{record.title,jdbcType=VARCHAR},

     </if>

     <if test="record.authodId != null" >

       authod_id = #{record.authodId,jdbcType=INTEGER},

     </if>

     <if test="record.state != null" >

       state = #{record.state,jdbcType=VARCHAR},

     </if>

     <if test="record.featured != null" >

       featured = #{record.featured,jdbcType=TINYINT},

     </if>

     <if test="record.style != null" >

       style = #{record.style,jdbcType=VARCHAR},

     </if>

   </set>

   <if test="_parameter != null" >

     <include refid="Update_By_Example_Where_Clause" />

   </if>

 </update>

 <update id="updateByExample" parameterType="map" >

   update blog

   set id = #{record.id,jdbcType=INTEGER},

     title = #{record.title,jdbcType=VARCHAR},

     authod_id = #{record.authodId,jdbcType=INTEGER},

     state = #{record.state,jdbcType=VARCHAR},

     featured = #{record.featured,jdbcType=TINYINT},

     style = #{record.style,jdbcType=VARCHAR}

   <if test="_parameter != null" >

     <include refid="Update_By_Example_Where_Clause" />

   </if>

 </update>

</mapper>

com.geyao.mybatis.pojo

Blog

package com.geyao.mybatis.pojo;

 

public class Blog {

   private Integer id;

 

   private String title;

 

   private Integer authodId;

 

   private String state;

 

   private Byte featured;

 

   private String style;

 

   public Integer getId() {

       return id;

   }

 

   public void setId(Integer id) {

       this.id = id;

   }

 

   public String getTitle() {

       return title;

   }

 

   public void setTitle(String title) {

       this.title = title == null ? null : title.trim();

   }

 

   public Integer getAuthodId() {

       return authodId;

   }

 

   public void setAuthodId(Integer authodId) {

       this.authodId = authodId;

   }

 

   public String getState() {

       return state;

   }

 

   public void setState(String state) {

       this.state = state == null ? null : state.trim();

   }

 

   public Byte getFeatured() {

       return featured;

   }

 

   public void setFeatured(Byte featured) {

       this.featured = featured;

   }

 

   public String getStyle() {

       return style;

   }

 

   public void setStyle(String style) {

       this.style = style == null ? null : style.trim();

   }

}

BlogExample

package com.geyao.mybatis.pojo;

 

import java.util.ArrayList;

import java.util.List;

 

public class BlogExample {

   protected String orderByClause;

 

   protected boolean distinct;

 

   protected List<Criteria> oredCriteria;

 

   public BlogExample() {

       oredCriteria = new ArrayList<Criteria>();

   }

 

   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<Criterion>();

       }

 

       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));

       }

 

       public Criteria andIdIsNull() {

           addCriterion("id is null");

           return (Criteria) this;

       }

 

       public Criteria andIdIsNotNull() {

           addCriterion("id is not null");

           return (Criteria) this;

       }

 

       public Criteria andIdEqualTo(Integer value) {

           addCriterion("id =", value, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdNotEqualTo(Integer value) {

           addCriterion("id <>", value, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdGreaterThan(Integer value) {

           addCriterion("id >", value, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdGreaterThanOrEqualTo(Integer value) {

           addCriterion("id >=", value, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdLessThan(Integer value) {

           addCriterion("id <", value, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdLessThanOrEqualTo(Integer value) {

           addCriterion("id <=", value, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdIn(List<Integer> values) {

           addCriterion("id in", values, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdNotIn(List<Integer> values) {

           addCriterion("id not in", values, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdBetween(Integer value1, Integer value2) {

           addCriterion("id between", value1, value2, "id");

           return (Criteria) this;

       }

 

       public Criteria andIdNotBetween(Integer value1, Integer value2) {

           addCriterion("id not between", value1, value2, "id");

           return (Criteria) this;

       }

 

       public Criteria andTitleIsNull() {

           addCriterion("title is null");

           return (Criteria) this;

       }

 

       public Criteria andTitleIsNotNull() {

           addCriterion("title is not null");

           return (Criteria) this;

       }

 

       public Criteria andTitleEqualTo(String value) {

           addCriterion("title =", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleNotEqualTo(String value) {

           addCriterion("title <>", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleGreaterThan(String value) {

           addCriterion("title >", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleGreaterThanOrEqualTo(String value) {

           addCriterion("title >=", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleLessThan(String value) {

           addCriterion("title <", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleLessThanOrEqualTo(String value) {

           addCriterion("title <=", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleLike(String value) {

           addCriterion("title like", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleNotLike(String value) {

           addCriterion("title not like", value, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleIn(List<String> values) {

           addCriterion("title in", values, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleNotIn(List<String> values) {

           addCriterion("title not in", values, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleBetween(String value1, String value2) {

           addCriterion("title between", value1, value2, "title");

           return (Criteria) this;

       }

 

       public Criteria andTitleNotBetween(String value1, String value2) {

           addCriterion("title not between", value1, value2, "title");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdIsNull() {

           addCriterion("authod_id is null");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdIsNotNull() {

           addCriterion("authod_id is not null");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdEqualTo(Integer value) {

           addCriterion("authod_id =", value, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdNotEqualTo(Integer value) {

           addCriterion("authod_id <>", value, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdGreaterThan(Integer value) {

           addCriterion("authod_id >", value, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdGreaterThanOrEqualTo(Integer value) {

           addCriterion("authod_id >=", value, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdLessThan(Integer value) {

           addCriterion("authod_id <", value, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdLessThanOrEqualTo(Integer value) {

           addCriterion("authod_id <=", value, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdIn(List<Integer> values) {

           addCriterion("authod_id in", values, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdNotIn(List<Integer> values) {

           addCriterion("authod_id not in", values, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdBetween(Integer value1, Integer value2) {

           addCriterion("authod_id between", value1, value2, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andAuthodIdNotBetween(Integer value1, Integer value2) {

           addCriterion("authod_id not between", value1, value2, "authodId");

           return (Criteria) this;

       }

 

       public Criteria andStateIsNull() {

           addCriterion("state is null");

           return (Criteria) this;

       }

 

       public Criteria andStateIsNotNull() {

           addCriterion("state is not null");

           return (Criteria) this;

       }

 

       public Criteria andStateEqualTo(String value) {

           addCriterion("state =", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateNotEqualTo(String value) {

           addCriterion("state <>", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateGreaterThan(String value) {

           addCriterion("state >", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateGreaterThanOrEqualTo(String value) {

           addCriterion("state >=", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateLessThan(String value) {

           addCriterion("state <", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateLessThanOrEqualTo(String value) {

           addCriterion("state <=", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateLike(String value) {

           addCriterion("state like", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateNotLike(String value) {

           addCriterion("state not like", value, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateIn(List<String> values) {

           addCriterion("state in", values, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateNotIn(List<String> values) {

           addCriterion("state not in", values, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateBetween(String value1, String value2) {

           addCriterion("state between", value1, value2, "state");

           return (Criteria) this;

       }

 

       public Criteria andStateNotBetween(String value1, String value2) {

           addCriterion("state not between", value1, value2, "state");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedIsNull() {

           addCriterion("featured is null");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedIsNotNull() {

           addCriterion("featured is not null");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedEqualTo(Byte value) {

           addCriterion("featured =", value, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedNotEqualTo(Byte value) {

           addCriterion("featured <>", value, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedGreaterThan(Byte value) {

           addCriterion("featured >", value, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedGreaterThanOrEqualTo(Byte value) {

           addCriterion("featured >=", value, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedLessThan(Byte value) {

           addCriterion("featured <", value, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedLessThanOrEqualTo(Byte value) {

           addCriterion("featured <=", value, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedIn(List<Byte> values) {

           addCriterion("featured in", values, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedNotIn(List<Byte> values) {

           addCriterion("featured not in", values, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedBetween(Byte value1, Byte value2) {

           addCriterion("featured between", value1, value2, "featured");

           return (Criteria) this;

       }

 

       public Criteria andFeaturedNotBetween(Byte value1, Byte value2) {

           addCriterion("featured not between", value1, value2, "featured");

           return (Criteria) this;

       }

 

       public Criteria andStyleIsNull() {

           addCriterion("style is null");

           return (Criteria) this;

       }

 

       public Criteria andStyleIsNotNull() {

           addCriterion("style is not null");

           return (Criteria) this;

       }

 

       public Criteria andStyleEqualTo(String value) {

           addCriterion("style =", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleNotEqualTo(String value) {

           addCriterion("style <>", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleGreaterThan(String value) {

           addCriterion("style >", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleGreaterThanOrEqualTo(String value) {

           addCriterion("style >=", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleLessThan(String value) {

           addCriterion("style <", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleLessThanOrEqualTo(String value) {

           addCriterion("style <=", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleLike(String value) {

           addCriterion("style like", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleNotLike(String value) {

           addCriterion("style not like", value, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleIn(List<String> values) {

           addCriterion("style in", values, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleNotIn(List<String> values) {

           addCriterion("style not in", values, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleBetween(String value1, String value2) {

           addCriterion("style between", value1, value2, "style");

           return (Criteria) this;

       }

 

       public Criteria andStyleNotBetween(String value1, String value2) {

           addCriterion("style not between", value1, value2, "style");

           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);

       }

   }

}

com.geyao.mybatis.util

MybatisUtil

package com.geyao.mybatis.util;

 

import java.io.InputStream;

import java.io.Reader;

 

import org.apache.ibatis.io.Resources;

import org.apache.ibatis.session.SqlSession;

import org.apache.ibatis.session.SqlSessionFactory;

import org.apache.ibatis.session.SqlSessionFactoryBuilder;

 

public class MyBatisUtil {

   private static SqlSessionFactory sqlSessionFactory =null;

   static {

       try {

           InputStream in = Resources.getResourceAsStream("mybatis-config.xml");

           sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);

       } catch (Exception e) {

           // TODO Auto-generated catch block

           e.printStackTrace();

       }

   }

   private MyBatisUtil() {}

 

   public static SqlSession getSqlSession() {

       return sqlSessionFactory.openSession();

   }

}

com.geyao.mybatis.mapper

BlogMapperTest

package com.geyao.mybatis.mapper;

 

import java.util.ArrayList;

import java.util.List;

 

import org.apache.ibatis.session.SqlSession;

import org.junit.Test;

 

import com.geyao.mybatis.pojo.Blog;

import com.geyao.mybatis.pojo.BlogExample;

import com.geyao.mybatis.pojo.BlogExample.Criteria;

import com.geyao.mybatis.util.MyBatisUtil;

 

public class BlogMapperTest {

   @Test

   public void testSelect() {

       SqlSession session =MyBatisUtil.getSqlSession();

       BlogMapper blogMapper =session.getMapper(BlogMapper.class);

       BlogExample blogExample=new BlogExample();

       BlogExample.Criteria blogcriteria=blogExample.createCriteria();

       blogcriteria.andTitleLike("%g%");

     

       List<Blog> blogList=blogMapper.selectByExample(blogExample);

       System.out.print(blogList);

   }

}

运行结果

image.png

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
1月前
|
SQL 缓存 Java
【详细实用のMyBatis教程】获取参数值和结果的各种情况、自定义映射、动态SQL、多级缓存、逆向工程、分页插件
本文详细介绍了MyBatis的各种常见用法MyBatis多级缓存、逆向工程、分页插件 包括获取参数值和结果的各种情况、自定义映射resultMap、动态SQL
【详细实用のMyBatis教程】获取参数值和结果的各种情况、自定义映射、动态SQL、多级缓存、逆向工程、分页插件
|
25天前
|
Java 数据库连接 数据库
spring和Mybatis的逆向工程
通过本文的介绍,我们了解了如何使用Spring和MyBatis进行逆向工程,包括环境配置、MyBatis Generator配置、Spring和MyBatis整合以及业务逻辑的编写。逆向工程极大地提高了开发效率,减少了重复劳动,保证了代码的一致性和可维护性。希望这篇文章能帮助你在项目中高效地使用Spring和MyBatis。
15 1
|
2月前
|
Java 数据库连接 Maven
mybatis使用一:springboot整合mybatis、mybatis generator,使用逆向工程生成java代码。
这篇文章介绍了如何在Spring Boot项目中整合MyBatis和MyBatis Generator,使用逆向工程来自动生成Java代码,包括实体类、Mapper文件和Example文件,以提高开发效率。
145 2
mybatis使用一:springboot整合mybatis、mybatis generator,使用逆向工程生成java代码。
|
2月前
|
Java 关系型数据库 MySQL
springboot学习五:springboot整合Mybatis 连接 mysql数据库
这篇文章是关于如何使用Spring Boot整合MyBatis来连接MySQL数据库,并进行基本的增删改查操作的教程。
202 0
springboot学习五:springboot整合Mybatis 连接 mysql数据库
|
7月前
|
Java 数据库连接 数据库
Mybatis逆向工程笔记小结
Mybatis逆向工程笔记小结
|
3月前
|
Java 关系型数据库 数据库连接
mybatis-plus学习
MyBatis-Plus ,MyBatis 最佳搭档,只做增强不做改变,为简化开发、提高效率而生。
51 5
|
4月前
|
安全 Java 数据库连接
后端框架的学习----mybatis框架(3、配置解析)
这篇文章详细介绍了MyBatis框架的核心配置文件解析,包括环境配置、属性配置、类型别名设置、映射器注册以及SqlSessionFactory和SqlSession的生命周期和作用域管理。
后端框架的学习----mybatis框架(3、配置解析)
|
4月前
|
Java 数据库连接 mybatis
后端框架的学习----mybatis框架(9、多对一处理和一对多处理)
这篇文章介绍了在MyBatis框架中如何处理多对一和一对多的关联查询,通过定义`<resultMap>`和使用`<association>`与`<collection>`元素来实现对象间的关联映射。
|
4月前
|
Java 数据库连接 测试技术
后端框架的学习----mybatis框架(8、lombok)
这篇文章介绍了如何在MyBatis框架中使用lombok库来简化Java实体类的编写,包括在IDEA中安装Lombok插件、在项目中导入lombok依赖以及在实体类上使用Lombok提供的注解。
|
4月前
|
Java 数据库连接 数据库
后端框架的学习----mybatis框架(6、日志)
这篇文章介绍了如何在MyBatis框架中使用日志功能,包括配置MyBatis的日志实现、使用log4j作为日志工具,以及如何通过配置文件控制日志级别和输出格式。
下一篇
DataWorks