mybatis-generator.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>
<context id="cosmetic" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接地址账号密码-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/diary?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false" userId="root" password="666666">
<!-- 防止生成字段不全 -->
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
userId="scott"
password="0000">
</jdbcConnection> -->
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成pojo类存放位置-->
<javaModelGenerator targetPackage="com.diary.generator.pojo" targetProject="src/main/java">
<!-- 是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false"/>
<!-- 从数据库返回的值清理前后的空格 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射文件mapper接口存放位置-->
<sqlMapGenerator targetPackage="com.diary.generator.mapper" targetProject="src/main/java">
<!-- 是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!--生成mapper接口、mapper.xml类存放位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.diary.generator.mapper" targetProject="src/main/java">
<!-- 是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!--生成对应表及类名,需要记住的一点是逆向工程无法生成关联关系,只能生成单表操作-->
<table tableName="user" domainObjectName="User" />
<!-- <table tableName="permission" domainObjectName="Permission" />
<table tableName="role" domainObjectName="Role" />
<table tableName="role_permission" domainObjectName="RolePermission" />
<table tableName="user_role" domainObjectName="UserRole" /> -->
</context>
</generatorConfiguration>
测试
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
//指向逆向工程配置文件
File configFile = new File("src/main/resources/mybatis-generator.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);
}
网友评论