利用mybatis-generator自动生成代码
Posted Learning notes
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用mybatis-generator自动生成代码相关的知识,希望对你有一定的参考价值。
-
在pom.xml中添加plugin
注意: <plugins> 与 <pluginManagement> 同级
<plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.7</version> <configuration> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version>2.3.0</version> </dependency> </dependencies> </plugin> </plugins>
-
generatorConfig.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="mysql" targetRuntime="MyBatis3Simple"> <commentGenerator> <property name="suppressDate" value="true"/> </commentGenerator> <!-- 数据库连接 --> <jdbcConnection driverClass="org.mariadb.jdbc.Driver" connectionURL="jdbc:mariadb://localhost/xx" userId="xxx" password="xxx"> </jdbcConnection> <!-- Model生成规则 --> <javaModelGenerator targetPackage="com.lhy.Flower.entity" targetProject="src/main/java"> <property name="trimStrings" value="true"/> </javaModelGenerator> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/> <!-- dao 规则 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.lhy.flower.dao" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <table tableName="%"> <generatedKey column="id" sqlStatement="Mysql"/> </table> </context> </generatorConfiguration>
-
最后给出目录结构图:
以上是关于利用mybatis-generator自动生成代码的主要内容,如果未能解决你的问题,请参考以下文章
spring boot中利用mybatis-generator插件生成代码
利用mybatis-generator自动生成表实例类和映射文件