MybatisGenerator 数据库逆向生成代码工具
2017-06-01 10:29
337 查看
一、依赖jar包
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.29</version> </dependency>
二、核心配置文件: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="GCCSMysql" targetRuntime="MyBatis3" defaultModelType="flat"> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <property name="mergeable" value="false"></property> <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"/> <commentGenerator> <!-- 抑制警告 --> <property name="suppressTypeWarnings" value="true"/> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="false"/> <property name="javaFileEncoding" value="UTF-8"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/db_test_user?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true" userId="root" password="root"> </jdbcConnection> <javaModelGenerator targetPackage="com.mybatis.test.model.user" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <sqlMapGenerator targetPackage="com.mybatis.test.mapper.user" targetProject="src/main/resources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <javaClientGenerator targetPackage="com.mybatis.test.mapper.user" targetProject="src/main/java" type="XMLMAPPER"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <table tableName="t_custom" domainObjectName="Custom" enableInsert="true" enableSelectByPrimaryKey="true" enableSelectByExample="true" enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="true" enableDeleteByExample="true" enableCountByExample="true" enableUpdateByExample="true" selectByPrimaryKeyQueryId="true" selectByExampleQueryId="true"> </table> <table tableName="t_seller" domainObjectName="Seller" enableInsert="true" enableSelectByPrimaryKey="true" enableSelectByExample="true" enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="true" enableDeleteByExample="true" enableCountByExample="true" enableUpdateByExample="true" selectByPrimaryKeyQueryId="true" selectByExampleQueryId="true"> </table> </context> </generatorConfiguration>
三、maven pom添加编译配置
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <encoding>UTF-8</encoding> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.0.0</version> </plugin> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <verbose>false</verbose> <overwrite>false</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.41</version> </dependency> </dependencies> </plugin> </plugins> </build>
四、运行
之后弹出运行配置框,为当前配置配置一个名称,这里其名为"generator",然后在 “Command line” 选项中输入“mybatis-generator:generate
-e”
这里加了“-e ”选项是为了让该插件输出详细信息,这样可以帮助我们定位问题。
如果添加成功,则会在run 选项中有“generator” 选项,如下:
点击运行
相关推荐:
快速搭建springboot项目
springboot集成mybatis
springboot集成hibernate
相关文章推荐
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 数据库逆向代码生成工具:MyBatis Generator的使用
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 数据库逆向框架代码生成工具:MyBatis Generator的使用
- 代码生成工具系列--------(三)根据数据库,生成存储过程
- CSharp数据库代码生成工具
- Tool工具生成代码数据库Model生成代码
- Mybatis逆向工程根据数据库表生成java代码。
- 数据库字段属性配置工具界面[用于代码生成]
- [c#]一步一步开发自己的自动代码生成工具之一:获取sql2005的数据库表结构
- [C#]一步一步开发自己的自动代码生成工具之一:获取SQL2005的数据库表结构
- 编写自己的代码生成工具四:数据库信息查询实现
- Tool工具生成代码数据库Model生成代码
- 代码生成工具系列--------(二)根据数据库,得到必要的信息