@Mybatis-Plus代码生成器
mybatis-plus依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- mybatis-plus代码生成器 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.1</version>
</dependency>
.properties配置文件
server.port=8080
# druid
#spring.datasource.druid.master.url=
spring.datasource.druid.master.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true
#spring.datasource.druid.master.username=
spring.datasource.druid.master.username=root
#spring.datasource.druid.master.password=
spring.datasource.druid.master.password=123456
spring.datasource.druid.master.driver-class-name=com.mysql.jdbc.Driver
定义MyBatisCodeGenerator
public class MyBatisCodeGenerator {
public static void main(String[] args) throws Exception {
System.out.println("+++++++++generate begin++++++++++");
List<String> warnings = new ArrayList<String>();
boolean overwrite = true ;
String url = MyBatisCodeGenerator.class.getResource("/MBG_configuration.xml").getFile();
File configFile = new File(url);
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("+++++++++generate writer end+++++++++++");
}
}
定义MBG_configuration.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>
<!-- <classPathEntry-->
<!-- location="C:/Oracle/Middleware/wlserver_10.3/server/lib/ojdbc6.jar"/>-->
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- <jdbcConnection driverClass="org.postgresql.Driver"-->
<!-- connectionURL="jdbc:postgresql://127.0.0.1:5432/postgres?useSSL=false"-->
<!-- userId="gpadmin"-->
<!-- password="pivotal"/>-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test?useUnicode=true;characterEncoding=utf-8;allowMultiQueries=true;useSSL=false;allowPublicKeyRetrieval=true"
userId="root"
password="123456"/>
<javaModelGenerator targetPackage="com.demo.entity"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="mapper"
targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.demo.mapper"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--<table tableName="T_FEE_AGTBILL" domainObjectName="FeeAgentBill"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>-->
<!-- <table tableName="import_user_errors" domainObjectName="ImportUserErrors"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="organization" domainObjectName="Organization"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="platform_roles" domainObjectName="PlatformRoles"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="v_refact_role_resources" domainObjectName="VRefactRoleResource"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<table tableName="test" domainObjectName="test"
enableCountByExample="true"
enableUpdateByExample="true" enableDeleteByExample="true"
enableSelectByExample="true" selectByExampleQueryId="true"
enableInsert="true" enableUpdateByPrimaryKey="true"
enableDeleteByPrimaryKey="true">
<!--<columnRenamingRule searchString="^D_"
replaceString=""/>-->
</table>
<!-- <table tableName="users" domainObjectName="User"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="projects" domainObjectName="Project"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="resources" domainObjectName="Resource"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="role_resources" domainObjectName="RoleResource"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="roles" domainObjectName="Role"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="system_connections" domainObjectName="SystemConnection"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="systems" domainObjectName="System"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="user_organization" domainObjectName="UserOrganization"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="user_resources" domainObjectName="UserResource"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="user_roles" domainObjectName="UserRole"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="user_system" domainObjectName="UserSystem"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="data_models" domainObjectName="DataModel"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="data_model_detail" domainObjectName="DataModelDetail"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
<!-- <table tableName="users" domainObjectName="User"-->
<!-- enableCountByExample="true"-->
<!-- enableUpdateByExample="true" enableDeleteByExample="true"-->
<!-- enableSelectByExample="true" selectByExampleQueryId="true"-->
<!-- enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!-- enableDeleteByPrimaryKey="true">-->
<!-- <!–<columnRenamingRule searchString="^D_"-->
<!-- replaceString=""/>–>-->
<!-- </table>-->
</context>
</generatorConfiguration>
链接: link.