11.1、正向与逆向工程概述

  • 正向工程:先创建Java实体类,由框架负责根据实体类生成数据库表;例如Hibernate是支持正向工程的。

  • 逆向工程:先创建数据库表,由框架负责根据数据库表,反向生成Java实体类、mapper接口和映射文件。

11.2、环境搭建

11.2.1、创建新module

创建名为mybatis_mbg的新module,过程参考5.1节

11.2.2、添加打包方式和依赖及插件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>org.rain</groupId>
  7. <artifactId>mybatis_mbg</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <!--打包方式-->
  10. <packaging>jar</packaging>
  11. <!--依赖-->
  12. <dependencies>
  13. <!-- Mybatis核心 -->
  14. <dependency>
  15. <groupId>org.mybatis</groupId>
  16. <artifactId>mybatis</artifactId>
  17. <version>3.5.7</version>
  18. </dependency>
  19. <!-- junit测试 -->
  20. <dependency>
  21. <groupId>junit</groupId>
  22. <artifactId>junit</artifactId>
  23. <version>4.12</version>
  24. <scope>test</scope>
  25. </dependency>
  26. <!-- MySQL驱动 -->
  27. <dependency>
  28. <groupId>mysql</groupId>
  29. <artifactId>mysql-connector-java</artifactId>
  30. <version>5.1.49</version>
  31. </dependency>
  32. <!-- log4j日志 -->
  33. <dependency>
  34. <groupId>log4j</groupId>
  35. <artifactId>log4j</artifactId>
  36. <version>1.2.17</version>
  37. </dependency>
  38. </dependencies>
  39. <build>
  40. <!-- 构建过程中用到的插件 -->
  41. <plugins>
  42. <!-- 具体插件,逆向工程的操作是以构建过程中插件形式出现的 -->
  43. <plugin>
  44. <groupId>org.mybatis.generator</groupId>
  45. <artifactId>mybatis-generator-maven-plugin</artifactId>
  46. <version>1.3.0</version>
  47. <!-- 插件的依赖 -->
  48. <dependencies>
  49. <!-- 逆向工程的核心依赖 -->
  50. <dependency>
  51. <groupId>org.mybatis.generator</groupId>
  52. <artifactId>mybatis-generator-core</artifactId>
  53. <version>1.3.2</version>
  54. </dependency>
  55. <!-- MySQL驱动 -->
  56. <dependency>
  57. <groupId>mysql</groupId>
  58. <artifactId>mysql-connector-java</artifactId>
  59. <version>5.1.49</version>
  60. </dependency>
  61. </dependencies>
  62. </plugin>
  63. </plugins>
  64. </build>
  65. </project>

11.3、创建逆向工程的配置文件

注意:文件名必须是generatorConfig.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <!--
  7. targetRuntime属性: 设置执行生成逆向工程的版本
  8. MyBatis3Simple: 生成基本的CRUD(简洁版)
  9. MyBatis3: 生成带条件的CRUD(进阶版)
  10. -->
  11. <context id="DB2Tables" targetRuntime="MyBatis3Simple">
  12. <!-- 数据库的连接信息 -->
  13. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  14. connectionURL="jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8"
  15. userId="root"
  16. password="root">
  17. </jdbcConnection>
  18. <!-- javaBean的生成策略-->
  19. <javaModelGenerator targetPackage="org.rain.mybatis.pojo" targetProject=".\src\main\java">
  20. <property name="enableSubPackages" value="true" />
  21. <property name="trimStrings" value="true" />
  22. </javaModelGenerator>
  23. <!-- SQL映射文件的生成策略 -->
  24. <sqlMapGenerator targetPackage="org.rain.mybatis.mapper" targetProject=".\src\main\resources">
  25. <property name="enableSubPackages" value="true" />
  26. </sqlMapGenerator>
  27. <!-- Mapper接口的生成策略 -->
  28. <javaClientGenerator type="XMLMAPPER" targetPackage="org.rain.mybatis.mapper" targetProject=".\src\main\java">
  29. <property name="enableSubPackages" value="true" />
  30. </javaClientGenerator>
  31. <!-- 逆向分析的表 -->
  32. <!-- tableName设置为*号,可以对应所有表,此时不写domainObjectName -->
  33. <!-- domainObjectName属性指定生成出来的实体类的类名 -->
  34. <table tableName="t_emp" domainObjectName="Emp"/>
  35. <table tableName="t_dept" domainObjectName="Dept"/>
  36. </context>
  37. </generatorConfiguration>

11.4、执行mybatis-generator插件

  • 找到mybatis-generator插件,并双击执行

11.5、插件执行效果(简洁版)

11.5.1、总体概览

注意:如图所示,实体类、接口和映射文件都自动生成了

11.5.2、实体类生成内容示例

  1. package org.rain.mybatis.pojo;
  2. public class Dept {
  3. /**
  4. * This field was generated by MyBatis Generator.
  5. * This field corresponds to the database column t_dept.dept_id
  6. *
  7. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  8. */
  9. private Integer deptId;
  10. /**
  11. * This field was generated by MyBatis Generator.
  12. * This field corresponds to the database column t_dept.dept_name
  13. *
  14. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  15. */
  16. private String deptName;
  17. /**
  18. * This method was generated by MyBatis Generator.
  19. * This method returns the value of the database column t_dept.dept_id
  20. *
  21. * @return the value of t_dept.dept_id
  22. *
  23. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  24. */
  25. public Integer getDeptId() {
  26. return deptId;
  27. }
  28. /**
  29. * This method was generated by MyBatis Generator.
  30. * This method sets the value of the database column t_dept.dept_id
  31. *
  32. * @param deptId the value for t_dept.dept_id
  33. *
  34. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  35. */
  36. public void setDeptId(Integer deptId) {
  37. this.deptId = deptId;
  38. }
  39. /**
  40. * This method was generated by MyBatis Generator.
  41. * This method returns the value of the database column t_dept.dept_name
  42. *
  43. * @return the value of t_dept.dept_name
  44. *
  45. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  46. */
  47. public String getDeptName() {
  48. return deptName;
  49. }
  50. /**
  51. * This method was generated by MyBatis Generator.
  52. * This method sets the value of the database column t_dept.dept_name
  53. *
  54. * @param deptName the value for t_dept.dept_name
  55. *
  56. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  57. */
  58. public void setDeptName(String deptName) {
  59. this.deptName = deptName == null ? null : deptName.trim();
  60. }
  61. }

11.5.3、mapper接口生成内容示例

  1. package org.rain.mybatis.mapper;
  2. import java.util.List;
  3. import org.rain.mybatis.pojo.Dept;
  4. public interface DeptMapper {
  5. /**
  6. * This method was generated by MyBatis Generator.
  7. * This method corresponds to the database table t_dept
  8. *
  9. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  10. */
  11. int deleteByPrimaryKey(Integer deptId);
  12. /**
  13. * This method was generated by MyBatis Generator.
  14. * This method corresponds to the database table t_dept
  15. *
  16. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  17. */
  18. int insert(Dept record);
  19. /**
  20. * This method was generated by MyBatis Generator.
  21. * This method corresponds to the database table t_dept
  22. *
  23. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  24. */
  25. Dept selectByPrimaryKey(Integer deptId);
  26. /**
  27. * This method was generated by MyBatis Generator.
  28. * This method corresponds to the database table t_dept
  29. *
  30. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  31. */
  32. List<Dept> selectAll();
  33. /**
  34. * This method was generated by MyBatis Generator.
  35. * This method corresponds to the database table t_dept
  36. *
  37. * @mbggenerated Wed Jul 05 11:25:17 CST 2023
  38. */
  39. int updateByPrimaryKey(Dept record);
  40. }

11.5.4、映射文件生成内容示例

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="org.rain.mybatis.mapper.DeptMapper" >
  4. <resultMap id="BaseResultMap" type="org.rain.mybatis.pojo.Dept" >
  5. <!--
  6. WARNING - @mbggenerated
  7. This element is automatically generated by MyBatis Generator, do not modify.
  8. This element was generated on Wed Jul 05 11:25:17 CST 2023.
  9. -->
  10. <id column="dept_id" property="deptId" jdbcType="INTEGER" />
  11. <result column="dept_name" property="deptName" jdbcType="VARCHAR" />
  12. </resultMap>
  13. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  14. <!--
  15. WARNING - @mbggenerated
  16. This element is automatically generated by MyBatis Generator, do not modify.
  17. This element was generated on Wed Jul 05 11:25:17 CST 2023.
  18. -->
  19. delete from t_dept
  20. where dept_id = #{deptId,jdbcType=INTEGER}
  21. </delete>
  22. <insert id="insert" parameterType="org.rain.mybatis.pojo.Dept" >
  23. <!--
  24. WARNING - @mbggenerated
  25. This element is automatically generated by MyBatis Generator, do not modify.
  26. This element was generated on Wed Jul 05 11:25:17 CST 2023.
  27. -->
  28. insert into t_dept (dept_id, dept_name)
  29. values (#{deptId,jdbcType=INTEGER}, #{deptName,jdbcType=VARCHAR})
  30. </insert>
  31. <update id="updateByPrimaryKey" parameterType="org.rain.mybatis.pojo.Dept" >
  32. <!--
  33. WARNING - @mbggenerated
  34. This element is automatically generated by MyBatis Generator, do not modify.
  35. This element was generated on Wed Jul 05 11:25:17 CST 2023.
  36. -->
  37. update t_dept
  38. set dept_name = #{deptName,jdbcType=VARCHAR}
  39. where dept_id = #{deptId,jdbcType=INTEGER}
  40. </update>
  41. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  42. <!--
  43. WARNING - @mbggenerated
  44. This element is automatically generated by MyBatis Generator, do not modify.
  45. This element was generated on Wed Jul 05 11:25:17 CST 2023.
  46. -->
  47. select dept_id, dept_name
  48. from t_dept
  49. where dept_id = #{deptId,jdbcType=INTEGER}
  50. </select>
  51. <select id="selectAll" resultMap="BaseResultMap" >
  52. <!--
  53. WARNING - @mbggenerated
  54. This element is automatically generated by MyBatis Generator, do not modify.
  55. This element was generated on Wed Jul 05 11:25:17 CST 2023.
  56. -->
  57. select dept_id, dept_name
  58. from t_dept
  59. </select>
  60. </mapper>

11.6、进阶版逆向工程

11.6.1、修改逆向工程配置文件

11.6.2、删除之前简单版生成的内容

++++++++++++++++++++分割线++++++++++++++++++++++

11.6.3、执行mybatis-generator插件

11.6.4、插件执行效果(进阶版)

11.6.4.1、总体概览

注意:进阶版生成的实体类,比简洁版的多了xxxExample

11.6.4.2、实体类生成内容示例

  1. package org.rain.mybatis.pojo;
  2. public class Dept {
  3. /**
  4. * This field was generated by MyBatis Generator.
  5. * This field corresponds to the database column t_dept.dept_id
  6. *
  7. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  8. */
  9. private Integer deptId;
  10. /**
  11. * This field was generated by MyBatis Generator.
  12. * This field corresponds to the database column t_dept.dept_name
  13. *
  14. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  15. */
  16. private String deptName;
  17. /**
  18. * This method was generated by MyBatis Generator.
  19. * This method returns the value of the database column t_dept.dept_id
  20. *
  21. * @return the value of t_dept.dept_id
  22. *
  23. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  24. */
  25. public Integer getDeptId() {
  26. return deptId;
  27. }
  28. /**
  29. * This method was generated by MyBatis Generator.
  30. * This method sets the value of the database column t_dept.dept_id
  31. *
  32. * @param deptId the value for t_dept.dept_id
  33. *
  34. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  35. */
  36. public void setDeptId(Integer deptId) {
  37. this.deptId = deptId;
  38. }
  39. /**
  40. * This method was generated by MyBatis Generator.
  41. * This method returns the value of the database column t_dept.dept_name
  42. *
  43. * @return the value of t_dept.dept_name
  44. *
  45. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  46. */
  47. public String getDeptName() {
  48. return deptName;
  49. }
  50. /**
  51. * This method was generated by MyBatis Generator.
  52. * This method sets the value of the database column t_dept.dept_name
  53. *
  54. * @param deptName the value for t_dept.dept_name
  55. *
  56. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  57. */
  58. public void setDeptName(String deptName) {
  59. this.deptName = deptName == null ? null : deptName.trim();
  60. }
  61. }

11.6.4.3、实体类Example生成内容示例

  1. package org.rain.mybatis.pojo;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. public class DeptExample {
  5. /**
  6. * This field was generated by MyBatis Generator.
  7. * This field corresponds to the database table t_dept
  8. *
  9. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  10. */
  11. protected String orderByClause;
  12. /**
  13. * This field was generated by MyBatis Generator.
  14. * This field corresponds to the database table t_dept
  15. *
  16. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  17. */
  18. protected boolean distinct;
  19. /**
  20. * This field was generated by MyBatis Generator.
  21. * This field corresponds to the database table t_dept
  22. *
  23. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  24. */
  25. protected List<Criteria> oredCriteria;
  26. /**
  27. * This method was generated by MyBatis Generator.
  28. * This method corresponds to the database table t_dept
  29. *
  30. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  31. */
  32. public DeptExample() {
  33. oredCriteria = new ArrayList<Criteria>();
  34. }
  35. /**
  36. * This method was generated by MyBatis Generator.
  37. * This method corresponds to the database table t_dept
  38. *
  39. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  40. */
  41. public void setOrderByClause(String orderByClause) {
  42. this.orderByClause = orderByClause;
  43. }
  44. /**
  45. * This method was generated by MyBatis Generator.
  46. * This method corresponds to the database table t_dept
  47. *
  48. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  49. */
  50. public String getOrderByClause() {
  51. return orderByClause;
  52. }
  53. /**
  54. * This method was generated by MyBatis Generator.
  55. * This method corresponds to the database table t_dept
  56. *
  57. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  58. */
  59. public void setDistinct(boolean distinct) {
  60. this.distinct = distinct;
  61. }
  62. /**
  63. * This method was generated by MyBatis Generator.
  64. * This method corresponds to the database table t_dept
  65. *
  66. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  67. */
  68. public boolean isDistinct() {
  69. return distinct;
  70. }
  71. /**
  72. * This method was generated by MyBatis Generator.
  73. * This method corresponds to the database table t_dept
  74. *
  75. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  76. */
  77. public List<Criteria> getOredCriteria() {
  78. return oredCriteria;
  79. }
  80. /**
  81. * This method was generated by MyBatis Generator.
  82. * This method corresponds to the database table t_dept
  83. *
  84. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  85. */
  86. public void or(Criteria criteria) {
  87. oredCriteria.add(criteria);
  88. }
  89. /**
  90. * This method was generated by MyBatis Generator.
  91. * This method corresponds to the database table t_dept
  92. *
  93. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  94. */
  95. public Criteria or() {
  96. Criteria criteria = createCriteriaInternal();
  97. oredCriteria.add(criteria);
  98. return criteria;
  99. }
  100. /**
  101. * This method was generated by MyBatis Generator.
  102. * This method corresponds to the database table t_dept
  103. *
  104. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  105. */
  106. public Criteria createCriteria() {
  107. Criteria criteria = createCriteriaInternal();
  108. if (oredCriteria.size() == 0) {
  109. oredCriteria.add(criteria);
  110. }
  111. return criteria;
  112. }
  113. /**
  114. * This method was generated by MyBatis Generator.
  115. * This method corresponds to the database table t_dept
  116. *
  117. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  118. */
  119. protected Criteria createCriteriaInternal() {
  120. Criteria criteria = new Criteria();
  121. return criteria;
  122. }
  123. /**
  124. * This method was generated by MyBatis Generator.
  125. * This method corresponds to the database table t_dept
  126. *
  127. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  128. */
  129. public void clear() {
  130. oredCriteria.clear();
  131. orderByClause = null;
  132. distinct = false;
  133. }
  134. /**
  135. * This class was generated by MyBatis Generator.
  136. * This class corresponds to the database table t_dept
  137. *
  138. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  139. */
  140. protected abstract static class GeneratedCriteria {
  141. protected List<Criterion> criteria;
  142. protected GeneratedCriteria() {
  143. super();
  144. criteria = new ArrayList<Criterion>();
  145. }
  146. public boolean isValid() {
  147. return criteria.size() > 0;
  148. }
  149. public List<Criterion> getAllCriteria() {
  150. return criteria;
  151. }
  152. public List<Criterion> getCriteria() {
  153. return criteria;
  154. }
  155. protected void addCriterion(String condition) {
  156. if (condition == null) {
  157. throw new RuntimeException("Value for condition cannot be null");
  158. }
  159. criteria.add(new Criterion(condition));
  160. }
  161. protected void addCriterion(String condition, Object value, String property) {
  162. if (value == null) {
  163. throw new RuntimeException("Value for " + property + " cannot be null");
  164. }
  165. criteria.add(new Criterion(condition, value));
  166. }
  167. protected void addCriterion(String condition, Object value1, Object value2, String property) {
  168. if (value1 == null || value2 == null) {
  169. throw new RuntimeException("Between values for " + property + " cannot be null");
  170. }
  171. criteria.add(new Criterion(condition, value1, value2));
  172. }
  173. public Criteria andDeptIdIsNull() {
  174. addCriterion("dept_id is null");
  175. return (Criteria) this;
  176. }
  177. public Criteria andDeptIdIsNotNull() {
  178. addCriterion("dept_id is not null");
  179. return (Criteria) this;
  180. }
  181. public Criteria andDeptIdEqualTo(Integer value) {
  182. addCriterion("dept_id =", value, "deptId");
  183. return (Criteria) this;
  184. }
  185. public Criteria andDeptIdNotEqualTo(Integer value) {
  186. addCriterion("dept_id <>", value, "deptId");
  187. return (Criteria) this;
  188. }
  189. public Criteria andDeptIdGreaterThan(Integer value) {
  190. addCriterion("dept_id >", value, "deptId");
  191. return (Criteria) this;
  192. }
  193. public Criteria andDeptIdGreaterThanOrEqualTo(Integer value) {
  194. addCriterion("dept_id >=", value, "deptId");
  195. return (Criteria) this;
  196. }
  197. public Criteria andDeptIdLessThan(Integer value) {
  198. addCriterion("dept_id <", value, "deptId");
  199. return (Criteria) this;
  200. }
  201. public Criteria andDeptIdLessThanOrEqualTo(Integer value) {
  202. addCriterion("dept_id <=", value, "deptId");
  203. return (Criteria) this;
  204. }
  205. public Criteria andDeptIdIn(List<Integer> values) {
  206. addCriterion("dept_id in", values, "deptId");
  207. return (Criteria) this;
  208. }
  209. public Criteria andDeptIdNotIn(List<Integer> values) {
  210. addCriterion("dept_id not in", values, "deptId");
  211. return (Criteria) this;
  212. }
  213. public Criteria andDeptIdBetween(Integer value1, Integer value2) {
  214. addCriterion("dept_id between", value1, value2, "deptId");
  215. return (Criteria) this;
  216. }
  217. public Criteria andDeptIdNotBetween(Integer value1, Integer value2) {
  218. addCriterion("dept_id not between", value1, value2, "deptId");
  219. return (Criteria) this;
  220. }
  221. public Criteria andDeptNameIsNull() {
  222. addCriterion("dept_name is null");
  223. return (Criteria) this;
  224. }
  225. public Criteria andDeptNameIsNotNull() {
  226. addCriterion("dept_name is not null");
  227. return (Criteria) this;
  228. }
  229. public Criteria andDeptNameEqualTo(String value) {
  230. addCriterion("dept_name =", value, "deptName");
  231. return (Criteria) this;
  232. }
  233. public Criteria andDeptNameNotEqualTo(String value) {
  234. addCriterion("dept_name <>", value, "deptName");
  235. return (Criteria) this;
  236. }
  237. public Criteria andDeptNameGreaterThan(String value) {
  238. addCriterion("dept_name >", value, "deptName");
  239. return (Criteria) this;
  240. }
  241. public Criteria andDeptNameGreaterThanOrEqualTo(String value) {
  242. addCriterion("dept_name >=", value, "deptName");
  243. return (Criteria) this;
  244. }
  245. public Criteria andDeptNameLessThan(String value) {
  246. addCriterion("dept_name <", value, "deptName");
  247. return (Criteria) this;
  248. }
  249. public Criteria andDeptNameLessThanOrEqualTo(String value) {
  250. addCriterion("dept_name <=", value, "deptName");
  251. return (Criteria) this;
  252. }
  253. public Criteria andDeptNameLike(String value) {
  254. addCriterion("dept_name like", value, "deptName");
  255. return (Criteria) this;
  256. }
  257. public Criteria andDeptNameNotLike(String value) {
  258. addCriterion("dept_name not like", value, "deptName");
  259. return (Criteria) this;
  260. }
  261. public Criteria andDeptNameIn(List<String> values) {
  262. addCriterion("dept_name in", values, "deptName");
  263. return (Criteria) this;
  264. }
  265. public Criteria andDeptNameNotIn(List<String> values) {
  266. addCriterion("dept_name not in", values, "deptName");
  267. return (Criteria) this;
  268. }
  269. public Criteria andDeptNameBetween(String value1, String value2) {
  270. addCriterion("dept_name between", value1, value2, "deptName");
  271. return (Criteria) this;
  272. }
  273. public Criteria andDeptNameNotBetween(String value1, String value2) {
  274. addCriterion("dept_name not between", value1, value2, "deptName");
  275. return (Criteria) this;
  276. }
  277. }
  278. /**
  279. * This class was generated by MyBatis Generator.
  280. * This class corresponds to the database table t_dept
  281. *
  282. * @mbggenerated do_not_delete_during_merge Thu Jul 06 11:01:56 CST 2023
  283. */
  284. public static class Criteria extends GeneratedCriteria {
  285. protected Criteria() {
  286. super();
  287. }
  288. }
  289. /**
  290. * This class was generated by MyBatis Generator.
  291. * This class corresponds to the database table t_dept
  292. *
  293. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  294. */
  295. public static class Criterion {
  296. private String condition;
  297. private Object value;
  298. private Object secondValue;
  299. private boolean noValue;
  300. private boolean singleValue;
  301. private boolean betweenValue;
  302. private boolean listValue;
  303. private String typeHandler;
  304. public String getCondition() {
  305. return condition;
  306. }
  307. public Object getValue() {
  308. return value;
  309. }
  310. public Object getSecondValue() {
  311. return secondValue;
  312. }
  313. public boolean isNoValue() {
  314. return noValue;
  315. }
  316. public boolean isSingleValue() {
  317. return singleValue;
  318. }
  319. public boolean isBetweenValue() {
  320. return betweenValue;
  321. }
  322. public boolean isListValue() {
  323. return listValue;
  324. }
  325. public String getTypeHandler() {
  326. return typeHandler;
  327. }
  328. protected Criterion(String condition) {
  329. super();
  330. this.condition = condition;
  331. this.typeHandler = null;
  332. this.noValue = true;
  333. }
  334. protected Criterion(String condition, Object value, String typeHandler) {
  335. super();
  336. this.condition = condition;
  337. this.value = value;
  338. this.typeHandler = typeHandler;
  339. if (value instanceof List<?>) {
  340. this.listValue = true;
  341. } else {
  342. this.singleValue = true;
  343. }
  344. }
  345. protected Criterion(String condition, Object value) {
  346. this(condition, value, null);
  347. }
  348. protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
  349. super();
  350. this.condition = condition;
  351. this.value = value;
  352. this.secondValue = secondValue;
  353. this.typeHandler = typeHandler;
  354. this.betweenValue = true;
  355. }
  356. protected Criterion(String condition, Object value, Object secondValue) {
  357. this(condition, value, secondValue, null);
  358. }
  359. }
  360. }

11.6.4.4、mapper接口生成内容示例

  1. package org.rain.mybatis.mapper;
  2. import java.util.List;
  3. import org.apache.ibatis.annotations.Param;
  4. import org.rain.mybatis.pojo.Dept;
  5. import org.rain.mybatis.pojo.DeptExample;
  6. public interface DeptMapper {
  7. /**
  8. * This method was generated by MyBatis Generator.
  9. * This method corresponds to the database table t_dept
  10. *
  11. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  12. */
  13. int countByExample(DeptExample example);
  14. /**
  15. * This method was generated by MyBatis Generator.
  16. * This method corresponds to the database table t_dept
  17. *
  18. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  19. */
  20. int deleteByExample(DeptExample example);
  21. /**
  22. * This method was generated by MyBatis Generator.
  23. * This method corresponds to the database table t_dept
  24. *
  25. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  26. */
  27. int deleteByPrimaryKey(Integer deptId);
  28. /**
  29. * This method was generated by MyBatis Generator.
  30. * This method corresponds to the database table t_dept
  31. *
  32. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  33. */
  34. int insert(Dept record);
  35. /**
  36. * This method was generated by MyBatis Generator.
  37. * This method corresponds to the database table t_dept
  38. *
  39. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  40. */
  41. int insertSelective(Dept record);
  42. /**
  43. * This method was generated by MyBatis Generator.
  44. * This method corresponds to the database table t_dept
  45. *
  46. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  47. */
  48. List<Dept> selectByExample(DeptExample example);
  49. /**
  50. * This method was generated by MyBatis Generator.
  51. * This method corresponds to the database table t_dept
  52. *
  53. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  54. */
  55. Dept selectByPrimaryKey(Integer deptId);
  56. /**
  57. * This method was generated by MyBatis Generator.
  58. * This method corresponds to the database table t_dept
  59. *
  60. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  61. */
  62. int updateByExampleSelective(@Param("record") Dept record, @Param("example") DeptExample example);
  63. /**
  64. * This method was generated by MyBatis Generator.
  65. * This method corresponds to the database table t_dept
  66. *
  67. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  68. */
  69. int updateByExample(@Param("record") Dept record, @Param("example") DeptExample example);
  70. /**
  71. * This method was generated by MyBatis Generator.
  72. * This method corresponds to the database table t_dept
  73. *
  74. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  75. */
  76. int updateByPrimaryKeySelective(Dept record);
  77. /**
  78. * This method was generated by MyBatis Generator.
  79. * This method corresponds to the database table t_dept
  80. *
  81. * @mbggenerated Thu Jul 06 11:01:56 CST 2023
  82. */
  83. int updateByPrimaryKey(Dept record);
  84. }

11.6.4.5、映射文件生成内容示例

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="org.rain.mybatis.mapper.DeptMapper" >
  4. <resultMap id="BaseResultMap" type="org.rain.mybatis.pojo.Dept" >
  5. <!--
  6. WARNING - @mbggenerated
  7. This element is automatically generated by MyBatis Generator, do not modify.
  8. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  9. -->
  10. <id column="dept_id" property="deptId" jdbcType="INTEGER" />
  11. <result column="dept_name" property="deptName" jdbcType="VARCHAR" />
  12. </resultMap>
  13. <sql id="Example_Where_Clause" >
  14. <!--
  15. WARNING - @mbggenerated
  16. This element is automatically generated by MyBatis Generator, do not modify.
  17. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  18. -->
  19. <where >
  20. <foreach collection="oredCriteria" item="criteria" separator="or" >
  21. <if test="criteria.valid" >
  22. <trim prefix="(" suffix=")" prefixOverrides="and" >
  23. <foreach collection="criteria.criteria" item="criterion" >
  24. <choose >
  25. <when test="criterion.noValue" >
  26. and ${criterion.condition}
  27. </when>
  28. <when test="criterion.singleValue" >
  29. and ${criterion.condition} #{criterion.value}
  30. </when>
  31. <when test="criterion.betweenValue" >
  32. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  33. </when>
  34. <when test="criterion.listValue" >
  35. and ${criterion.condition}
  36. <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
  37. #{listItem}
  38. </foreach>
  39. </when>
  40. </choose>
  41. </foreach>
  42. </trim>
  43. </if>
  44. </foreach>
  45. </where>
  46. </sql>
  47. <sql id="Update_By_Example_Where_Clause" >
  48. <!--
  49. WARNING - @mbggenerated
  50. This element is automatically generated by MyBatis Generator, do not modify.
  51. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  52. -->
  53. <where >
  54. <foreach collection="example.oredCriteria" item="criteria" separator="or" >
  55. <if test="criteria.valid" >
  56. <trim prefix="(" suffix=")" prefixOverrides="and" >
  57. <foreach collection="criteria.criteria" item="criterion" >
  58. <choose >
  59. <when test="criterion.noValue" >
  60. and ${criterion.condition}
  61. </when>
  62. <when test="criterion.singleValue" >
  63. and ${criterion.condition} #{criterion.value}
  64. </when>
  65. <when test="criterion.betweenValue" >
  66. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  67. </when>
  68. <when test="criterion.listValue" >
  69. and ${criterion.condition}
  70. <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
  71. #{listItem}
  72. </foreach>
  73. </when>
  74. </choose>
  75. </foreach>
  76. </trim>
  77. </if>
  78. </foreach>
  79. </where>
  80. </sql>
  81. <sql id="Base_Column_List" >
  82. <!--
  83. WARNING - @mbggenerated
  84. This element is automatically generated by MyBatis Generator, do not modify.
  85. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  86. -->
  87. dept_id, dept_name
  88. </sql>
  89. <select id="selectByExample" resultMap="BaseResultMap" parameterType="org.rain.mybatis.pojo.DeptExample" >
  90. <!--
  91. WARNING - @mbggenerated
  92. This element is automatically generated by MyBatis Generator, do not modify.
  93. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  94. -->
  95. select
  96. <if test="distinct" >
  97. distinct
  98. </if>
  99. <include refid="Base_Column_List" />
  100. from t_dept
  101. <if test="_parameter != null" >
  102. <include refid="Example_Where_Clause" />
  103. </if>
  104. <if test="orderByClause != null" >
  105. order by ${orderByClause}
  106. </if>
  107. </select>
  108. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  109. <!--
  110. WARNING - @mbggenerated
  111. This element is automatically generated by MyBatis Generator, do not modify.
  112. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  113. -->
  114. select
  115. <include refid="Base_Column_List" />
  116. from t_dept
  117. where dept_id = #{deptId,jdbcType=INTEGER}
  118. </select>
  119. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  120. <!--
  121. WARNING - @mbggenerated
  122. This element is automatically generated by MyBatis Generator, do not modify.
  123. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  124. -->
  125. delete from t_dept
  126. where dept_id = #{deptId,jdbcType=INTEGER}
  127. </delete>
  128. <delete id="deleteByExample" parameterType="org.rain.mybatis.pojo.DeptExample" >
  129. <!--
  130. WARNING - @mbggenerated
  131. This element is automatically generated by MyBatis Generator, do not modify.
  132. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  133. -->
  134. delete from t_dept
  135. <if test="_parameter != null" >
  136. <include refid="Example_Where_Clause" />
  137. </if>
  138. </delete>
  139. <insert id="insert" parameterType="org.rain.mybatis.pojo.Dept" >
  140. <!--
  141. WARNING - @mbggenerated
  142. This element is automatically generated by MyBatis Generator, do not modify.
  143. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  144. -->
  145. insert into t_dept (dept_id, dept_name)
  146. values (#{deptId,jdbcType=INTEGER}, #{deptName,jdbcType=VARCHAR})
  147. </insert>
  148. <insert id="insertSelective" parameterType="org.rain.mybatis.pojo.Dept" >
  149. <!--
  150. WARNING - @mbggenerated
  151. This element is automatically generated by MyBatis Generator, do not modify.
  152. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  153. -->
  154. insert into t_dept
  155. <trim prefix="(" suffix=")" suffixOverrides="," >
  156. <if test="deptId != null" >
  157. dept_id,
  158. </if>
  159. <if test="deptName != null" >
  160. dept_name,
  161. </if>
  162. </trim>
  163. <trim prefix="values (" suffix=")" suffixOverrides="," >
  164. <if test="deptId != null" >
  165. #{deptId,jdbcType=INTEGER},
  166. </if>
  167. <if test="deptName != null" >
  168. #{deptName,jdbcType=VARCHAR},
  169. </if>
  170. </trim>
  171. </insert>
  172. <select id="countByExample" parameterType="org.rain.mybatis.pojo.DeptExample" resultType="java.lang.Integer" >
  173. <!--
  174. WARNING - @mbggenerated
  175. This element is automatically generated by MyBatis Generator, do not modify.
  176. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  177. -->
  178. select count(*) from t_dept
  179. <if test="_parameter != null" >
  180. <include refid="Example_Where_Clause" />
  181. </if>
  182. </select>
  183. <update id="updateByExampleSelective" parameterType="map" >
  184. <!--
  185. WARNING - @mbggenerated
  186. This element is automatically generated by MyBatis Generator, do not modify.
  187. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  188. -->
  189. update t_dept
  190. <set >
  191. <if test="record.deptId != null" >
  192. dept_id = #{record.deptId,jdbcType=INTEGER},
  193. </if>
  194. <if test="record.deptName != null" >
  195. dept_name = #{record.deptName,jdbcType=VARCHAR},
  196. </if>
  197. </set>
  198. <if test="_parameter != null" >
  199. <include refid="Update_By_Example_Where_Clause" />
  200. </if>
  201. </update>
  202. <update id="updateByExample" parameterType="map" >
  203. <!--
  204. WARNING - @mbggenerated
  205. This element is automatically generated by MyBatis Generator, do not modify.
  206. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  207. -->
  208. update t_dept
  209. set dept_id = #{record.deptId,jdbcType=INTEGER},
  210. dept_name = #{record.deptName,jdbcType=VARCHAR}
  211. <if test="_parameter != null" >
  212. <include refid="Update_By_Example_Where_Clause" />
  213. </if>
  214. </update>
  215. <update id="updateByPrimaryKeySelective" parameterType="org.rain.mybatis.pojo.Dept" >
  216. <!--
  217. WARNING - @mbggenerated
  218. This element is automatically generated by MyBatis Generator, do not modify.
  219. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  220. -->
  221. update t_dept
  222. <set >
  223. <if test="deptName != null" >
  224. dept_name = #{deptName,jdbcType=VARCHAR},
  225. </if>
  226. </set>
  227. where dept_id = #{deptId,jdbcType=INTEGER}
  228. </update>
  229. <update id="updateByPrimaryKey" parameterType="org.rain.mybatis.pojo.Dept" >
  230. <!--
  231. WARNING - @mbggenerated
  232. This element is automatically generated by MyBatis Generator, do not modify.
  233. This element was generated on Thu Jul 06 11:01:56 CST 2023.
  234. -->
  235. update t_dept
  236. set dept_name = #{deptName,jdbcType=VARCHAR}
  237. where dept_id = #{deptId,jdbcType=INTEGER}
  238. </update>
  239. </mapper>

11.7、测试示例

11.7.1、引入相关配置文件

11.7.1.1、jdbc.properties

  1. jdbc.driver=com.mysql.jdbc.Driver
  2. jdbc.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8
  3. jdbc.username=root
  4. jdbc.password=root

11.7.1.2、mybatis-config.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE configuration
  3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <configuration>
  6. <properties resource="jdbc.properties"/>
  7. <settings>
  8. <!--将下划线映射为驼峰-->
  9. <setting name="mapUnderscoreToCamelCase" value="true"/>
  10. <!--开启延迟加载-->
  11. <!--<setting name="lazyLoadingEnabled" value="true"/>-->
  12. <!--开启二级缓存-->
  13. <setting name="cacheEnabled" value="true"/>
  14. </settings>
  15. <typeAliases>
  16. <package name="org.rain.mybatis.pojo"/>
  17. </typeAliases>
  18. <environments default="development">
  19. <environment id="development">
  20. <transactionManager type="JDBC"/>
  21. <dataSource type="POOLED">
  22. <property name="driver" value="${jdbc.driver}"/>
  23. <property name="url" value="${jdbc.url}"/>
  24. <property name="username" value="${jdbc.username}"/>
  25. <property name="password" value="${jdbc.password}"/>
  26. </dataSource>
  27. </environment>
  28. </environments>
  29. <mappers>
  30. <package name="org.rain.mybatis.mapper"/>
  31. </mappers>
  32. </configuration>

11.7.1.3、log4j.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
  3. <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  4. <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
  5. <param name="Encoding" value="UTF-8" />
  6. <layout class="org.apache.log4j.PatternLayout">
  7. <param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss,SSS} %m (%F:%L) \n" />
  8. </layout>
  9. </appender>
  10. <logger name="java.sql">
  11. <level value="debug" />
  12. </logger>
  13. <logger name="org.apache.ibatis">
  14. <level value="info" />
  15. </logger>
  16. <root>
  17. <level value="debug" />
  18. <appender-ref ref="STDOUT" />
  19. </root>
  20. </log4j:configuration>

11.7.2、创建获取SqlSession工具类

  1. package org.rain.mybatis.utils;
  2. import org.apache.ibatis.io.Resources;
  3. import org.apache.ibatis.session.SqlSession;
  4. import org.apache.ibatis.session.SqlSessionFactory;
  5. import org.apache.ibatis.session.SqlSessionFactoryBuilder;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. public class SqlSessionUtils {
  9. public static SqlSession getSqlSession(){
  10. SqlSession sqlSession = null;
  11. try {
  12. //读取MyBatis核心配置文件的输入流
  13. InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
  14. //创建SqlSessionFactoryBuilder对象
  15. SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
  16. //通过核心配置文件所对应的字节输入流创建工厂类SqlSessionFactory,用于生产SqlSession对象
  17. SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is);
  18. //创建自动提交事务的SqlSession对象
  19. sqlSession = sqlSessionFactory.openSession(true);
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. return sqlSession;
  24. }
  25. }

11.7.3、创建测试类

11.7.4、根据主键查询一条数据

注意:生成的实体类没有tostring方法,因此需要手动在实体类添加tostring方法才有相关输出

  1. @Test
  2. public void testMbg(){
  3. SqlSession sqlSession = SqlSessionUtils.getSqlSession();
  4. EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
  5. //根据主键查询一条数据
  6. Emp emp = empMapper.selectByPrimaryKey(1);
  7. System.out.println(emp);
  8. }

11.7.5、查询所有数据

注意:无条件查询(即xxxExample为null)就是查询所有

  1. @Test
  2. public void testMbg(){
  3. SqlSession sqlSession = SqlSessionUtils.getSqlSession();
  4. EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
  5. //查询所有数据
  6. List<Emp> emps = empMapper.selectByExample(null);
  7. for (Emp emp : emps) {
  8. System.out.println(emp);
  9. }
  10. }

11.7.6、多条件查询(QBC风格)

  1. @Test
  2. public void testMbg(){
  3. SqlSession sqlSession = SqlSessionUtils.getSqlSession();
  4. EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
  5. //多条件查询,QBC(query by condition)风格
  6. EmpExample empExample = new EmpExample();
  7. empExample.createCriteria().andEmpNameEqualTo("小红").andEmpIdBetween(8,10);
  8. empExample.or().andAgeEqualTo(20);
  9. List<Emp> emps = empMapper.selectByExample(empExample);
  10. for (Emp emp : emps) {
  11. System.out.println(emp);
  12. }
  13. }

11.7.7、普通修改

++++++++++++++++++++++++分割线++++++++++++++++++++++++

++++++++++++++++++++++++分割线++++++++++++++++++++++++

注意:如图所示,普通修改会将显式设置为null或未设置的字段都修改为null

  1. @Test
  2. public void testMbg(){
  3. SqlSession sqlSession = SqlSessionUtils.getSqlSession();
  4. EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
  5. Emp emp = new Emp();
  6. emp.setEmpId(4);
  7. emp.setEmpName("小军");
  8. emp.setAge(null);
  9. emp.setGender("女");
  10. empMapper.updateByPrimaryKey(emp);
  11. }

11.7.8、选择性修改

++++++++++++++++++++++++分割线++++++++++++++++++++++++

++++++++++++++++++++++++分割线++++++++++++++++++++++++

注意:如图所示,选择性修改不会将显式设置为null或未设置的字段修改为null

  1. @Test
  2. public void testMbg(){
  3. SqlSession sqlSession = SqlSessionUtils.getSqlSession();
  4. EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
  5. Emp emp = new Emp();
  6. emp.setEmpId(3);
  7. emp.setEmpName("小军");
  8. emp.setAge(null);
  9. emp.setGender("女");
  10. empMapper.updateByPrimaryKeySelective(emp);
  11. }

11、Mybatis之逆向工程的更多相关文章

  1. mybatis学习系列四--mybatis generator逆向工程

    采用命令行方式执行逆向工程 1.配置文件generatorConfig.xml 保存在目录:D:\E\workspace\eclipse\mybatis_generator <?xmlversi ...

  2. 创建mybatis的逆向工程

    1.mybatis的逆向工程(我使用的是maven仓库创建) 工作原理:反向工程(通过数据库中的表和字段信息去生成对应的增删改查方法) 其实就是一个自动生成工具 生成实体类(pojo)和映射文件(ma ...

  3. mybatis的逆向工程

    mybatis的逆向工程是很大的减少了程序员对代码的编写工作,由于mybatis是半自动的sql语句使用,我们在项目中一般都是采用逆向工程来生成mybatis的文件,mapper接口相当于我们平常所说 ...

  4. Mybatis(七) mybatis的逆向工程的配置详解

    还是觉得看书学习有意思~嘿嘿.今天把mybatis给结束掉. --WH 一.什么是逆向工程? 简单点说,就是通过数据库中的单表,自动生成java代码. Mybatis官方提供了逆向工程,可以针对单表自 ...

  5. Mybatis【逆向工程,缓存,代理】知识要点

    前言 本文主要讲解Mybatis的以下知识点: Mybatis缓存 一级缓存 二级缓存 与Ehcache整合 Mapper代理 使用Mapper代理就不用写实现类了 逆向工程 自动生成代码 Mybat ...

  6. Mybatis学习(七)————— mybatis的逆向工程的配置详解

    一.什么是逆向工程? 简单点说,就是通过数据库中的单表,自动生成java代码. Mybatis官方提供了逆向工程,可以针对单表自动生成mybatis代码(mapper.java\mapper.xml\ ...

  7. SpringBoot+Mybatis+Generator 逆向工程使用(二)

    Mybatis-Genarator 逆向工程使用 个人开发环境 java环境:Jdk1.8.0_60 编译器:IntelliJ IDEA 2017.1.4 mysql驱动:mysql-connecto ...

  8. 【MyBatis学习15】MyBatis的逆向工程生成代码

    1. 什么是逆向工程 mybatis的一个主要的特点就是需要程序员自己编写sql,那么如果表太多的话,难免会很麻烦,所以mybatis官方提供了一个逆向工程,可以针对单表自动生成mybatis执行所需 ...

  9. Mybatis的逆向工程以及Example的实例函数及详解

    Mybatis-generator是Mybatis的逆向工程  (根据数据库中的表生成java代码) Mybatis的逆向工程会生成实例及实例对应的example,example用于添加条件,相当于w ...

  10. Mybatis Generator逆向工程的使用

    一.在 idea 中使用 mybatis generator 逆向工程 1.在IDEA上创建maven工程. 2.在pom.xml中配置MyBatis逆向工程插件 <!--MyBatis自动生成 ...

随机推荐

  1. ue全家桶进阶之路30:Vue3定义组件和常用指令

    要定义 Vue 3 组件,你可以使用 Vue 3 提供的 defineComponent 函数. 例如,以下是一个简单的 Vue 3 组件定义: import { defineComponent } ...

  2. 2023-05-20:go语言的slice和rust语言的Vec的扩容流程是什么?

    2023-05-20:go语言的slice和rust语言的Vec的扩容流程是什么? 答案2023-05-20: go语言的slice扩容流程 go版本是1.20.4. 扩容流程见源码见runtime/ ...

  3. 计算机网络OSI七层参考模型和tcp/udp五层参考模型

    计算机网络OSI七层参考模型和tcp/udp五层参考模型 目录 一.OSI七层参考模型和TCP/UDP五层参考模型 1.应用层 2.表示层 3.会话层 4.传输层 5.网络层 6.数据链路层 7.物理 ...

  4. < Python全景系列-8 > Python超薄感知,超强保护:异常处理的绝佳实践

    欢迎来到我们的系列博客<Python全景系列>!在这个系列中,我们将带领你从Python的基础知识开始,一步步深入到高级话题,帮助你掌握这门强大而灵活的编程语法.无论你是编程新手,还是有一 ...

  5. Java(数组使用、Arrays、稀疏数组)

    1.数组的使用 For-Each循环 int[] arrays = {1,2,3,4,5}; //打印全部的数组元素 JDK1.5 没有下标 for (int array : arrays) { Sy ...

  6. Hive执行计划之hive依赖及权限查询和常见使用场景

    目录 概述 1.explain dependency的查询与使用 2.借助explain dependency解决一些常见问题 2.1.识别看似等价的SQL代码实际上是不等价的: 2.2 通过expl ...

  7. Spring Boot 通用对象列表比较和去重

    1.前言   在Excel批量导入数据时,常常需要与数据库中已存在数据的比较,并且需要考虑导入数据重复的可能性.   导入的行数据,一般有一个实体类(对象)与之对应,往往这个实体类在数据库中的字段要比 ...

  8. Rust的类型系统

    Rust的类型系统 类型于20世纪50年代被FORTRAN语言引入,其相关的理论和应用已经发展得非常成熟.现在,类型系统已经成为了各大编程语言的核心基础. 通用基础 所谓类型,就是对表示信息的值进行的 ...

  9. 300行代码模拟cdn

    这一生听过许多道理,但还是过不好这一生,这是因为缺少真正的动手实践,光听道理,缺少动手实践的过程,学习难免会让人觉得味同嚼蜡,所以我的分享都比较倾向于实践,在一次次动手实践的过程中感受知识原本纯真的模 ...

  10. go使用 github.com/influxdata/influxdb/client/v2 写数据到 influxdb

    转载请注明出处: 接入示例 使用 github.com/influxdata/influxdb/client/v2 依赖包向 InfluxDB 写入数据的示例代码: package main impo ...