标签:false 接口 rgs depend 代码生成 write mat bpa htm
MBG:Mybatis Generator(代码生成器)
文档http://mybatis.org/generator/configreference/xmlconfig.html
逆向工程:
maven依赖
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
public static void main(String[] args) throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("mbg.xml");//注意这一个参数即可
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
System.out.println("生成完毕");
}
MyBatis3生成没限制的各种动态条件查询
MyBatis3Simple:基础的增删改查,也就是不会生成xxxExample,mapper文件只有简单的增删改查
<?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>
?
<!--targetRuntime
MyBatis3:生成没限制的各种动态条件查询
MyBatis3Simple:基础的增删改查
-->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true" />
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
?
<!--连接数据库-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/springboot_crud"
userId="root"
password="admin">
</jdbcConnection>
?
<!--默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer
为 true时把JDBC DECIMAL和 NUMERIC 类型解析为java.math.BigDecimal 主要是针对oracle数据库
-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
?
<!--生成pojo
targetPackage:生成的pojo放哪个包下
targetProject:放那个工程下
-->
<javaModelGenerator targetPackage="com.wanglz.pojo" targetProject="src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
?
<!--sql映射文件生成器 , 指定生成xml文件的地方 -->
<sqlMapGenerator targetPackage="mybatis\mapper" targetProject="src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
?
<!--dao接口生成的地方-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.wanglz.dao" targetProject="src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
?
<!--table指定逆向生成那个数据表
tableName:数据表名,
domainObjectName:对应这个表的对象名
-->
<table tableName="user" domainObjectName="User" > </table>
<table tableName="employee" domainObjectName="Employee" > </table>
<table tableName="department" domainObjectName="Department" > </table>
?
</context>
</generatorConfiguration>
标签:false 接口 rgs depend 代码生成 write mat bpa htm
原文地址:https://www.cnblogs.com/wanglzstudy/p/13431722.html