一、新建Maven逆向工程的详细流程
mybaties的generator官网:http://www.mybatis.org/generator/
maven仓库:https://mvnrepository.com/
工程目录:

二、搭建Maven工程的详细步骤
2.1 在Maven仓库中搜索Mybatis Generator Core添加依赖
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>


2.2 在mybaties Generator官网下载xml配置文件
网址:http://www.mybatis.org/generator/configreference/xmlconfig.html
2.2.1 新建generatorConfig.xml配置文件

将拷贝的内容放在generatorConfig.xml文件中




2.3 添加build标签到pom.xml文件中
网址:http://www.mybatis.org/generator/running/runningWithMaven.html
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
</plugin>
</plugins>
</build>
2.4 运行

命令:mybatis-generator:generate

2.5 编译时出错
Window-Preference-Java-Install jre

2.6 运行结果

2.7 详细代码
generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 连接数据库时需要引用的数据库动态参数 -->
<properties resource="config/db.properties"/>
<!-- 指定驱动包的位置 -->
<!-- 在本地新建的Maven仓库中下载的离线Mysql的jar -->
<classPathEntry location="D:\Maven\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar" />
<!-- 配置数据库连接信息 -->
<!-- id属性的值为任意值,targetRuntime的值为MyBatis3 -->
<context id="mybatiesStudentTable" targetRuntime="MyBatis3">
<jdbcConnection driverClass="${driver}"
connectionURL="${url}" userId="${username}" password="${password}">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 设置生成的JavaBean实体类的保存位置 -->
<javaModelGenerator targetPackage="com.neuedu.mybaties.entity"
targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 设置XXDao.xml生成的位置Mapper.xml -->
<sqlMapGenerator targetPackage="com.neuedu.mybaties.dao"
targetProject=".\src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 设置mapper.java的生成位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.neuedu.mybaties.dao" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 可以存在多个表格 tableName的值为对应数据库中哪张表,domainObjectName生成的实体类的名称-->
<table tableName="student" domainObjectName="StudentGenerator">
</table>
</context>
</generatorConfiguration>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.neuedu.demo</groupId>
<artifactId>testMybatis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
<!--添加build运行 -->
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
</plugin>
</plugins>
</build>
</project>
db.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/mybaties?useUnicode=true&characterEncoding=utf-8
username=root
password=root123
build成功之后生成的工程目录

StudentGeneratorMapper.java
package com.neuedu.mybaties.dao;
import com.neuedu.mybaties.entity.StudentGenerator;
import com.neuedu.mybaties.entity.StudentGeneratorExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface StudentGeneratorMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
long countByExample(StudentGeneratorExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int deleteByExample(StudentGeneratorExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int deleteByPrimaryKey(Integer stuno);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int insert(StudentGenerator record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int insertSelective(StudentGenerator record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
List<StudentGenerator> selectByExample(StudentGeneratorExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
StudentGenerator selectByPrimaryKey(Integer stuno);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int updateByExampleSelective(@Param("record") StudentGenerator record, @Param("example") StudentGeneratorExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int updateByExample(@Param("record") StudentGenerator record, @Param("example") StudentGeneratorExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int updateByPrimaryKeySelective(StudentGenerator record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
int updateByPrimaryKey(StudentGenerator record);
}
StudentGenerator.java
package com.neuedu.mybaties.entity;
import java.util.Date;
public class StudentGenerator {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column student.stuno
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
private Integer stuno;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column student.stuname
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
private String stuname;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column student.gender
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
private String gender;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column student.birthday
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
private Date birthday;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column student.classno
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
private Integer classno;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column student.stuno
*
* @return the value of student.stuno
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public Integer getStuno() {
return stuno;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column student.stuno
*
* @param stuno the value for student.stuno
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void setStuno(Integer stuno) {
this.stuno = stuno;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column student.stuname
*
* @return the value of student.stuname
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public String getStuname() {
return stuname;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column student.stuname
*
* @param stuname the value for student.stuname
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void setStuname(String stuname) {
this.stuname = stuname == null ? null : stuname.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column student.gender
*
* @return the value of student.gender
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public String getGender() {
return gender;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column student.gender
*
* @param gender the value for student.gender
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void setGender(String gender) {
this.gender = gender == null ? null : gender.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column student.birthday
*
* @return the value of student.birthday
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public Date getBirthday() {
return birthday;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column student.birthday
*
* @param birthday the value for student.birthday
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column student.classno
*
* @return the value of student.classno
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public Integer getClassno() {
return classno;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column student.classno
*
* @param classno the value for student.classno
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void setClassno(Integer classno) {
this.classno = classno;
}
}
StudentGeneratorExample.java
package com.neuedu.mybaties.entity;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class StudentGeneratorExample {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
protected String orderByClause;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
protected boolean distinct;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
protected List<Criteria> oredCriteria;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public StudentGeneratorExample() {
oredCriteria = new ArrayList<Criteria>();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public String getOrderByClause() {
return orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public boolean isDistinct() {
return distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
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));
}
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<java.sql.Date>();
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 andStunoIsNull() {
addCriterion("stuno is null");
return (Criteria) this;
}
public Criteria andStunoIsNotNull() {
addCriterion("stuno is not null");
return (Criteria) this;
}
public Criteria andStunoEqualTo(Integer value) {
addCriterion("stuno =", value, "stuno");
return (Criteria) this;
}
public Criteria andStunoNotEqualTo(Integer value) {
addCriterion("stuno <>", value, "stuno");
return (Criteria) this;
}
public Criteria andStunoGreaterThan(Integer value) {
addCriterion("stuno >", value, "stuno");
return (Criteria) this;
}
public Criteria andStunoGreaterThanOrEqualTo(Integer value) {
addCriterion("stuno >=", value, "stuno");
return (Criteria) this;
}
public Criteria andStunoLessThan(Integer value) {
addCriterion("stuno <", value, "stuno");
return (Criteria) this;
}
public Criteria andStunoLessThanOrEqualTo(Integer value) {
addCriterion("stuno <=", value, "stuno");
return (Criteria) this;
}
public Criteria andStunoIn(List<Integer> values) {
addCriterion("stuno in", values, "stuno");
return (Criteria) this;
}
public Criteria andStunoNotIn(List<Integer> values) {
addCriterion("stuno not in", values, "stuno");
return (Criteria) this;
}
public Criteria andStunoBetween(Integer value1, Integer value2) {
addCriterion("stuno between", value1, value2, "stuno");
return (Criteria) this;
}
public Criteria andStunoNotBetween(Integer value1, Integer value2) {
addCriterion("stuno not between", value1, value2, "stuno");
return (Criteria) this;
}
public Criteria andStunameIsNull() {
addCriterion("stuname is null");
return (Criteria) this;
}
public Criteria andStunameIsNotNull() {
addCriterion("stuname is not null");
return (Criteria) this;
}
public Criteria andStunameEqualTo(String value) {
addCriterion("stuname =", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameNotEqualTo(String value) {
addCriterion("stuname <>", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameGreaterThan(String value) {
addCriterion("stuname >", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameGreaterThanOrEqualTo(String value) {
addCriterion("stuname >=", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameLessThan(String value) {
addCriterion("stuname <", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameLessThanOrEqualTo(String value) {
addCriterion("stuname <=", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameLike(String value) {
addCriterion("stuname like", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameNotLike(String value) {
addCriterion("stuname not like", value, "stuname");
return (Criteria) this;
}
public Criteria andStunameIn(List<String> values) {
addCriterion("stuname in", values, "stuname");
return (Criteria) this;
}
public Criteria andStunameNotIn(List<String> values) {
addCriterion("stuname not in", values, "stuname");
return (Criteria) this;
}
public Criteria andStunameBetween(String value1, String value2) {
addCriterion("stuname between", value1, value2, "stuname");
return (Criteria) this;
}
public Criteria andStunameNotBetween(String value1, String value2) {
addCriterion("stuname not between", value1, value2, "stuname");
return (Criteria) this;
}
public Criteria andGenderIsNull() {
addCriterion("gender is null");
return (Criteria) this;
}
public Criteria andGenderIsNotNull() {
addCriterion("gender is not null");
return (Criteria) this;
}
public Criteria andGenderEqualTo(String value) {
addCriterion("gender =", value, "gender");
return (Criteria) this;
}
public Criteria andGenderNotEqualTo(String value) {
addCriterion("gender <>", value, "gender");
return (Criteria) this;
}
public Criteria andGenderGreaterThan(String value) {
addCriterion("gender >", value, "gender");
return (Criteria) this;
}
public Criteria andGenderGreaterThanOrEqualTo(String value) {
addCriterion("gender >=", value, "gender");
return (Criteria) this;
}
public Criteria andGenderLessThan(String value) {
addCriterion("gender <", value, "gender");
return (Criteria) this;
}
public Criteria andGenderLessThanOrEqualTo(String value) {
addCriterion("gender <=", value, "gender");
return (Criteria) this;
}
public Criteria andGenderLike(String value) {
addCriterion("gender like", value, "gender");
return (Criteria) this;
}
public Criteria andGenderNotLike(String value) {
addCriterion("gender not like", value, "gender");
return (Criteria) this;
}
public Criteria andGenderIn(List<String> values) {
addCriterion("gender in", values, "gender");
return (Criteria) this;
}
public Criteria andGenderNotIn(List<String> values) {
addCriterion("gender not in", values, "gender");
return (Criteria) this;
}
public Criteria andGenderBetween(String value1, String value2) {
addCriterion("gender between", value1, value2, "gender");
return (Criteria) this;
}
public Criteria andGenderNotBetween(String value1, String value2) {
addCriterion("gender not between", value1, value2, "gender");
return (Criteria) this;
}
public Criteria andBirthdayIsNull() {
addCriterion("birthday is null");
return (Criteria) this;
}
public Criteria andBirthdayIsNotNull() {
addCriterion("birthday is not null");
return (Criteria) this;
}
public Criteria andBirthdayEqualTo(Date value) {
addCriterionForJDBCDate("birthday =", value, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayNotEqualTo(Date value) {
addCriterionForJDBCDate("birthday <>", value, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayGreaterThan(Date value) {
addCriterionForJDBCDate("birthday >", value, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayGreaterThanOrEqualTo(Date value) {
addCriterionForJDBCDate("birthday >=", value, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayLessThan(Date value) {
addCriterionForJDBCDate("birthday <", value, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayLessThanOrEqualTo(Date value) {
addCriterionForJDBCDate("birthday <=", value, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayIn(List<Date> values) {
addCriterionForJDBCDate("birthday in", values, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayNotIn(List<Date> values) {
addCriterionForJDBCDate("birthday not in", values, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayBetween(Date value1, Date value2) {
addCriterionForJDBCDate("birthday between", value1, value2, "birthday");
return (Criteria) this;
}
public Criteria andBirthdayNotBetween(Date value1, Date value2) {
addCriterionForJDBCDate("birthday not between", value1, value2, "birthday");
return (Criteria) this;
}
public Criteria andClassnoIsNull() {
addCriterion("classno is null");
return (Criteria) this;
}
public Criteria andClassnoIsNotNull() {
addCriterion("classno is not null");
return (Criteria) this;
}
public Criteria andClassnoEqualTo(Integer value) {
addCriterion("classno =", value, "classno");
return (Criteria) this;
}
public Criteria andClassnoNotEqualTo(Integer value) {
addCriterion("classno <>", value, "classno");
return (Criteria) this;
}
public Criteria andClassnoGreaterThan(Integer value) {
addCriterion("classno >", value, "classno");
return (Criteria) this;
}
public Criteria andClassnoGreaterThanOrEqualTo(Integer value) {
addCriterion("classno >=", value, "classno");
return (Criteria) this;
}
public Criteria andClassnoLessThan(Integer value) {
addCriterion("classno <", value, "classno");
return (Criteria) this;
}
public Criteria andClassnoLessThanOrEqualTo(Integer value) {
addCriterion("classno <=", value, "classno");
return (Criteria) this;
}
public Criteria andClassnoIn(List<Integer> values) {
addCriterion("classno in", values, "classno");
return (Criteria) this;
}
public Criteria andClassnoNotIn(List<Integer> values) {
addCriterion("classno not in", values, "classno");
return (Criteria) this;
}
public Criteria andClassnoBetween(Integer value1, Integer value2) {
addCriterion("classno between", value1, value2, "classno");
return (Criteria) this;
}
public Criteria andClassnoNotBetween(Integer value1, Integer value2) {
addCriterion("classno not between", value1, value2, "classno");
return (Criteria) this;
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table student
*
* @mbg.generated do_not_delete_during_merge Fri May 31 09:33:36 CST 2019
*/
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table student
*
* @mbg.generated Fri May 31 09:33:36 CST 2019
*/
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);
}
}
}
StudentGeneratorMapper.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.neuedu.mybaties.dao.StudentGeneratorMapper">
<resultMap id="BaseResultMap" type="com.neuedu.mybaties.entity.StudentGenerator">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
<id column="stuno" jdbcType="INTEGER" property="stuno" />
<result column="stuname" jdbcType="VARCHAR" property="stuname" />
<result column="gender" jdbcType="VARCHAR" property="gender" />
<result column="birthday" jdbcType="DATE" property="birthday" />
<result column="classno" jdbcType="INTEGER" property="classno" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<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 close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<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 close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
stuno, stuname, gender, birthday, classno
</sql>
<select id="selectByExample" parameterType="com.neuedu.mybaties.entity.StudentGeneratorExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from student
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
select
<include refid="Base_Column_List" />
from student
where stuno = #{stuno,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
delete from student
where stuno = #{stuno,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.neuedu.mybaties.entity.StudentGeneratorExample">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
delete from student
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.neuedu.mybaties.entity.StudentGenerator">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
insert into student (stuno, stuname, gender,
birthday, classno)
values (#{stuno,jdbcType=INTEGER}, #{stuname,jdbcType=VARCHAR}, #{gender,jdbcType=VARCHAR},
#{birthday,jdbcType=DATE}, #{classno,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.neuedu.mybaties.entity.StudentGenerator">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
insert into student
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="stuno != null">
stuno,
</if>
<if test="stuname != null">
stuname,
</if>
<if test="gender != null">
gender,
</if>
<if test="birthday != null">
birthday,
</if>
<if test="classno != null">
classno,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="stuno != null">
#{stuno,jdbcType=INTEGER},
</if>
<if test="stuname != null">
#{stuname,jdbcType=VARCHAR},
</if>
<if test="gender != null">
#{gender,jdbcType=VARCHAR},
</if>
<if test="birthday != null">
#{birthday,jdbcType=DATE},
</if>
<if test="classno != null">
#{classno,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.neuedu.mybaties.entity.StudentGeneratorExample" resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
select count(*) from student
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
update student
<set>
<if test="record.stuno != null">
stuno = #{record.stuno,jdbcType=INTEGER},
</if>
<if test="record.stuname != null">
stuname = #{record.stuname,jdbcType=VARCHAR},
</if>
<if test="record.gender != null">
gender = #{record.gender,jdbcType=VARCHAR},
</if>
<if test="record.birthday != null">
birthday = #{record.birthday,jdbcType=DATE},
</if>
<if test="record.classno != null">
classno = #{record.classno,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
update student
set stuno = #{record.stuno,jdbcType=INTEGER},
stuname = #{record.stuname,jdbcType=VARCHAR},
gender = #{record.gender,jdbcType=VARCHAR},
birthday = #{record.birthday,jdbcType=DATE},
classno = #{record.classno,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.neuedu.mybaties.entity.StudentGenerator">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
update student
<set>
<if test="stuname != null">
stuname = #{stuname,jdbcType=VARCHAR},
</if>
<if test="gender != null">
gender = #{gender,jdbcType=VARCHAR},
</if>
<if test="birthday != null">
birthday = #{birthday,jdbcType=DATE},
</if>
<if test="classno != null">
classno = #{classno,jdbcType=INTEGER},
</if>
</set>
where stuno = #{stuno,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.neuedu.mybaties.entity.StudentGenerator">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri May 31 09:33:36 CST 2019.
-->
update student
set stuname = #{stuname,jdbcType=VARCHAR},
gender = #{gender,jdbcType=VARCHAR},
birthday = #{birthday,jdbcType=DATE},
classno = #{classno,jdbcType=INTEGER}
where stuno = #{stuno,jdbcType=INTEGER}
</update>
</mapper>
本文详细介绍了如何使用Maven构建MyBatis Generator的逆向工程,包括在Maven仓库中添加依赖,下载并配置generatorConfig.xml,修改pom.xml,运行生成代码,解决编译错误,直至最终成功生成包括Mapper、Model和Example在内的各类文件。

373

被折叠的 条评论
为什么被折叠?



