mybatis逆向工程
废话不多说直奔主题
先看下目录结构
接下来是Maven配置
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <addResources>true</addResources> </configuration> </plugin> <!--逆向工程插件--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <configurationFile>/IDEL_GIT_WORKSPACE/spt/src/main/resources/generatorConfig.xml </configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.19</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency> <!--<dependency>--> <!--<groupId>tk.mybatis</groupId>--> <!--<artifactId>mapper</artifactId>--> <!--<version>3.3.9</version>--> <!--</dependency>--> </dependencies> </plugin> </plugins> </build>
接下来看配置
建一个config.properties文件,内容如下:
# 数据库配置
jdbc.driverClass=com.mysql.cj.jdbc.Driver//mysql8.0驱动
jdbc.url=jdbc:mysql://localhost:3306/quanxian?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true
jdbc.user=//改成自己的用户名
jdbc.password=//改成自己的密码
# 通用Mapper固定配置
mapper.plugin=tk.mybatis.mapper.generator.MapperPlugin
mapper.Mapper=tk.mybatis.mapper.common.Mapper
mapper.forceAnnotation=true
# 生成文件保存位置
targetModelPackage=dubbo.****.project.entry
targetXMLPackage=mapper
targetMapperPackage=dubbo.******.project.mapper
targetJavaProject=src/main/java
targetResourcesProject=src/main/resources
说明:***在此处的意思是第一幅图马赛克部门,可根据自己实际项目配置。
接下来看下generatorConfig.xml的相关配置
下面的各个table就是需要生成的表
<?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> <properties resource="config.properties"/> <context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat"> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <!--支持序列化--> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <!-- <plugin type="${mapper.plugin}"> <property name="mappers" value="${mapper.Mapper}"/> <property name="forceAnnotation" value="${mapper.forceAnnotation}" /> </plugin> --> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true"/> </commentGenerator> <jdbcConnection driverClass="${jdbc.driverClass}" connectionURL="${jdbc.url}" userId="${jdbc.user}" password="${jdbc.password}"> </jdbcConnection> <javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false"/> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true"/> </javaModelGenerator> <sqlMapGenerator targetPackage="${targetXMLPackage}" targetProject="${targetResourcesProject}"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <javaClientGenerator targetPackage="${targetMapperPackage}" targetProject="${targetJavaProject}" type="XMLMAPPER"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false"/> </javaClientGenerator> <!--全部表参与逆向工程--> <!--以下example为false,表示不会生成example类,否则将自动生成example类--> <!--<table schema="" tableName="%"--> <!--enableCountByExample="false"--> <!--enableUpdateByExample="false"--> <!--enableDeleteByExample="false"--> <!--enableSelectByExample="false"--> <!--selectByExampleQueryId="false">--> <!--</table>--> <!--指定某些表参与逆向工程--> <table tableName="qrtz_blob_triggers" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <!--指定某些表参与逆向工程--> <table tableName="qrtz_calendars" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <!--指定某些表参与逆向工程--> <table tableName="qrtz_cron_triggers" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <!--指定某些表参与逆向工程--> <table tableName="qrtz_fired_triggers" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <!--指定某些表参与逆向工程--> <table tableName="qrtz_job_details" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <!--指定某些表参与逆向工程--> <table tableName="qrtz_locks" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <!--指定某些表参与逆向工程--> <table tableName="qrtz_paused_trigger_grps" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <!--指定某些表参与逆向工程--> <table tableName="qrtz_scheduler_state" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="qrtz_simple_triggers" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="qrtz_simprop_triggers" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="qrtz_triggers" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context> </generatorConfiguration>
最后在Maven中敲下如下命令
:
本文来自博客园,作者:余生请多指教ANT,转载请注明原文链接:https://www.cnblogs.com/wangbiaohistory/articles/12088946.html