169 lines
30 KiB
HTML
169 lines
30 KiB
HTML
<p>一、pxm.xml中引入mybatis-generator并配置</p>
|
||
<p>在build节点下的plugins下添加org.mybatis.generator 示例代码如下:</p>
|
||
<div class="cnblogs_code">
|
||
<pre><span style="color: #0000ff;"><?</span><span style="color: #ff00ff;">xml version="1.0" encoding="UTF-8"</span><span style="color: #0000ff;">?></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">project </span><span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">="http://maven.apache.org/POM/4.0.0"</span><span style="color: #ff0000;"> xmlns:xsi</span><span style="color: #0000ff;">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: #ff0000;">
|
||
xsi:schemaLocation</span><span style="color: #0000ff;">="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">modelVersion</span><span style="color: #0000ff;">></span>4.0.0<span style="color: #0000ff;"></</span><span style="color: #800000;">modelVersion</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">parent</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>org.springframework.boot<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>spring-boot-starter-parent<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>2.2.6.RELEASE<span style="color: #0000ff;"></</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">relativePath</span><span style="color: #0000ff;">/></span> <span style="color: #008000;"><!--</span><span style="color: #008000;"> lookup parent from repository </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">parent</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>com.dcrenl.test<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>test<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>0.0.1-SNAPSHOT<span style="color: #0000ff;"></</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">name</span><span style="color: #0000ff;">></span>test<span style="color: #0000ff;"></</span><span style="color: #800000;">name</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">description</span><span style="color: #0000ff;">></span>Demo project for Spring Boot<span style="color: #0000ff;"></</span><span style="color: #800000;">description</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">properties</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">java.version</span><span style="color: #0000ff;">></span>1.8<span style="color: #0000ff;"></</span><span style="color: #800000;">java.version</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">properties</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">dependencies</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>org.mybatis.spring.boot<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>mybatis-spring-boot-starter<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>2.1.2<span style="color: #0000ff;"></</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>mysql<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>mysql-connector-java<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">scope</span><span style="color: #0000ff;">></span>runtime<span style="color: #0000ff;"></</span><span style="color: #800000;">scope</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>org.springframework.boot<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>spring-boot-starter-test<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">scope</span><span style="color: #0000ff;">></span>test<span style="color: #0000ff;"></</span><span style="color: #800000;">scope</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">exclusions</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">exclusion</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>org.junit.vintage<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>junit-vintage-engine<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">exclusion</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">exclusions</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">dependencies</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">build</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">plugins</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">plugin</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>org.springframework.boot<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>spring-boot-maven-plugin<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">plugin</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">plugin</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>org.mybatis.generator<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>mybatis-generator-maven-plugin<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">configuration</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">configurationFile</span><span style="color: #0000ff;">></span>src/main/resources/generatorConfig.xml<span style="color: #0000ff;"></</span><span style="color: #800000;">configurationFile</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">verbose</span><span style="color: #0000ff;">></span>true<span style="color: #0000ff;"></</span><span style="color: #800000;">verbose</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">overwrite</span><span style="color: #0000ff;">></span>true<span style="color: #0000ff;"></</span><span style="color: #800000;">overwrite</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">configuration</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;">加入下面这个依赖</span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">dependencies</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>mysql<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>mysql-connector-java<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>${mysql.version}<span style="color: #0000ff;"></</span><span style="color: #800000;">version</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">dependency</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">dependencies</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">plugin</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">plugins</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">build</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">project</span><span style="color: #0000ff;">></span></pre>
|
||
</div>
|
||
<p> </p>
|
||
<p>二、在resources文件夹下新建mybatis-generator配置xml文件,内容如下:</p>
|
||
<div class="cnblogs_code">
|
||
<pre><span style="color: #0000ff;"><?</span><span style="color: #ff00ff;">xml version="1.0" encoding="UTF-8"</span><span style="color: #0000ff;">?></span>
|
||
<span style="color: #0000ff;"><!</span><span style="color: #ff00ff;">DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 配置生成器 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">generatorConfiguration</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;">classPathEntry:数据库的JDBC驱动,换成你自己的驱动位置 可选 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> <classPathEntry location="C:\Users\dcrenl\.m2\repository\mysql\mysql-connector-java\8.0.19\mysql-connector-java-8.0.19.jar"/></span><span style="color: #008000;">--></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 一个数据库一个context,defaultModelType="flat" 大数据字段,不分表 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">context </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="MysqlTables"</span><span style="color: #ff0000;"> targetRuntime</span><span style="color: #0000ff;">="MyBatis3"</span><span style="color: #ff0000;"> defaultModelType</span><span style="color: #0000ff;">="flat"</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 自动识别数据库关键字,默认false,如果设置为true,根据SqlReservedWords中定义的关键字列表;一般保留默认值,遇到数据库关键字(Java关键字),使用columnOverride覆盖 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="autoDelimitKeywords"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="true"</span><span style="color: #0000ff;">/></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 生成的Java文件的编码 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="javaFileEncoding"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="utf-8"</span><span style="color: #0000ff;">/></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> beginningDelimiter和endingDelimiter:指明数据库的用于标记数据库对象名的符号,比如ORACLE就是双引号,MYSQL默认是`反引号; </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="beginningDelimiter"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="`"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="endingDelimiter"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="`"</span><span style="color: #0000ff;">/></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 格式化java代码 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="javaFormatter"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="org.mybatis.generator.api.dom.DefaultJavaFormatter"</span><span style="color: #0000ff;">/></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 格式化XML代码 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="xmlFormatter"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="org.mybatis.generator.api.dom.DefaultXmlFormatter"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">plugin </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="org.mybatis.generator.plugins.SerializablePlugin"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">plugin </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="org.mybatis.generator.plugins.ToStringPlugin"</span><span style="color: #0000ff;">/></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 注释 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">commentGenerator</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="suppressAllComments"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="true"</span><span style="color: #0000ff;">/></span><span style="color: #008000;"><!--</span><span style="color: #008000;"> 是否取消注释 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="suppressDate"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="false"</span><span style="color: #0000ff;">/></span> <span style="color: #008000;"><!--</span><span style="color: #008000;"> 是否生成注释代时间戳</span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">commentGenerator</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> jdbc连接</span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">jdbcConnection </span><span style="color: #ff0000;">driverClass</span><span style="color: #0000ff;">="com.mysql.cj.jdbc.Driver"</span><span style="color: #ff0000;">
|
||
connectionURL</span><span style="color: #0000ff;">="jdbc:mysql://localhost:3306/test?serverTimezone=UTC&amp;setUnicode=true&amp;characterEncoding=utf8"</span><span style="color: #ff0000;"> userId</span><span style="color: #0000ff;">="root"</span><span style="color: #ff0000;">
|
||
password</span><span style="color: #0000ff;">="root"</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 防止生成其它库的表 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="nullCatalogMeansCurrent"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="true"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">jdbcConnection</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 类型转换 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">javaTypeResolver</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="forceBigDecimals"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="false"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">javaTypeResolver</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 生成实体类地址 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">javaModelGenerator </span><span style="color: #ff0000;">targetPackage</span><span style="color: #0000ff;">="com.dcrenl.examinersystem.entity"</span><span style="color: #ff0000;"> targetProject</span><span style="color: #0000ff;">="src/main/java"</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 是否让schema作为包的后缀 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="enableSubPackages"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="false"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 从数据库返回的值去掉前后空格 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="trimStrings"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="true"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">javaModelGenerator</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 生成map.xml文件存放地址 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">sqlMapGenerator </span><span style="color: #ff0000;">targetPackage</span><span style="color: #0000ff;">="mapper"</span><span style="color: #ff0000;"> targetProject</span><span style="color: #0000ff;">="src/main/resources"</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="enableSubPackages"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="false"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">sqlMapGenerator</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> 生成接口dao(mapper) </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">javaClientGenerator </span><span style="color: #ff0000;">targetPackage</span><span style="color: #0000ff;">="com.dcrenl.examinersystem.mapper"</span><span style="color: #ff0000;"> targetProject</span><span style="color: #0000ff;">="src/main/java"</span><span style="color: #ff0000;"> type</span><span style="color: #0000ff;">="XMLMAPPER"</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="enableSubPackages"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="false"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="nullCatalogMeansCurrent"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="true"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">javaClientGenerator</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #008000;"><!--</span><span style="color: #008000;"> table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 </span><span style="color: #008000;">--></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">table </span><span style="color: #ff0000;">tableName</span><span style="color: #0000ff;">="t_%"</span><span style="color: #ff0000;">
|
||
enableCountByExample</span><span style="color: #0000ff;">="false"</span><span style="color: #ff0000;">
|
||
enableUpdateByExample</span><span style="color: #0000ff;">="false"</span><span style="color: #ff0000;">
|
||
enableDeleteByExample</span><span style="color: #0000ff;">="false"</span><span style="color: #ff0000;">
|
||
enableSelectByExample</span><span style="color: #0000ff;">="false"</span><span style="color: #ff0000;">
|
||
selectByExampleQueryId</span><span style="color: #0000ff;">="false"</span><span style="color: #ff0000;">
|
||
enableSelectByPrimaryKey</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
|
||
enableUpdateByPrimaryKey</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
|
||
enableDeleteByPrimaryKey</span><span style="color: #0000ff;">="true"</span>
|
||
<span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">property </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="useActualColumnNames"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="false"</span><span style="color: #0000ff;">/></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">table</span><span style="color: #0000ff;">></span>
|
||
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">context</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">generatorConfiguration</span><span style="color: #0000ff;">></span></pre>
|
||
</div>
|
||
<p>三、点击IDEA右侧“Maven”栏目,在“Plugins”中找到“mybatis-generator”展开找到“mybatis-generator:generate”,右键,“Run Maven Build” 生成</p>
|
||
<p> </p> |