Maven下 mybatis-generator使用
程序员文章站
2024-02-26 19:36:46
1. pom.xml下添加dependency
org.mybatis.generato...
1. pom.xml下添加dependency
<dependency> <groupid>org.mybatis.generator</groupid> <artifactid>mybatis-generator-core</artifactid> <version>1.3.2</version> </dependency>
2. pom.xml下plugins插入plugin
<plugin> <groupid>org.mybatis.generator</groupid> <artifactid>mybatis-generator-maven-plugin</artifactid> <version>1.3.2</version> <goals> <glal>generator</glal> </goals> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin>
3. src/main/resource下创建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> <classpathentry location="d:\repositorygit\mybatisgenerator1.3.5\mysql-connector-java-5.1.36.jar" /> <context id="mysqltables" targetruntime="mybatis3"> <!-- 生成的‘实体类'将implements serializable --> <plugin type="org.mybatis.generator.plugins.serializableplugin"></plugin> <!-- 是否生成注释--> <commentgenerator> <property name="suppressallcomments" value="true" /> <property name="suppressdate" value="true" /> </commentgenerator> <jdbcconnection driverclass="com.mysql.jdbc.driver" connectionurl="jdbc:mysql://127.0.0.1:3306/test" userid="root" password="mysql" /> <!--指定生成的类型为java类型,避免数据库中number等类型字段 --> <javatyperesolver> <property name="forcebigdecimals" value="false" /> </javatyperesolver> <!--自动生成的实体的存放包路径 --> <javamodelgenerator targetpackage="com.example.dao.mybatis.entity" targetproject="src/main/java"> <property name="enablesubpackages" value="true" /> <property name="trimstrings" value="true" /> </javamodelgenerator> <!--自动生成的*mapper.xml文件存放路径 --> <sqlmapgenerator targetpackage="com.example.dao.mybatis.sqlmap" targetproject="src/main/java"> <property name="enablesubpackages" value="true" /> </sqlmapgenerator> <!--自动生成的*mapper.java存放路径 --> <javaclientgenerator type="xmlmapper" targetpackage="com.example.dao.mybatis.mapper" targetproject="src/main/java"> <property name="enablesubpackages" value="true" /> </javaclientgenerator> <table tablename="user" domainobjectname="user" enablecountbyexample="false" enableupdatebyexample="false" enabledeletebyexample="false" enableselectbyexample="false" selectbyexamplequeryid="false"> <generatedkey column="id" sqlstatement="select last_insert_id()" identity="false" /> </table> </context> </generatorconfiguration>
4. 执行mybatis-generator:generate运行生成实体类、mapper和xml映射文件
总结
以上所述是小编给大家介绍的maven下 mybatis-generator使用,希望对大家有所帮助