Mybatis Generator自动生成代码
2016-08-16 10:52
225 查看
mybatis-generator有三种用法:命令行、eclipse插件、maven插件。个人觉得maven插件最方便,可以在eclipse/intellij idea等ide上可以通用。
pom.xml文件添加插件
generatorConfig.xml配置文件
运行
pom.xml文件添加插件
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.3</version> <configuration> <!-- 指定配置文件 --> <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.3</version> </dependency> </dependencies> </plugin>
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="C:/Users/Administrator/.m2/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar"/> <context id="my" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="false"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- 配置连接属性 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/admin-template" userId="root" password=""/> <!-- 配置model类生成位置 --> <javaModelGenerator targetPackage="org.springside.quickstart.entity" targetProject="D:/workspaces/java/admin-template/src/main/java"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 配置sqlMap文件生成位置 --> <sqlMapGenerator targetPackage="mybatis" targetProject="D:/workspaces/java/admin-template/src/main/resources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 配置mapper接口生成位置 --> <javaClientGenerator targetPackage="org.springside.quickstart.dao" targetProject="D:/workspaces/java/admin-template/src/main/java" type="XMLMAPPER"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 进行表配置 --> <table tableName="sys_user" domainObjectName="SysUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_role" domainObjectName="SysRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_permission" domainObjectName="SysPermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> <table tableName="sys_account" domainObjectName="SysAccount" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context> </generatorConfiguration>
运行
mvn mybatis-generator:generate
相关文章推荐
- .NET中利用XML来自动生成代码策略
- 一个自动生成用ADO调用SQL SERVER的存储过程VB代码的ADDIN
- 如何高效地使用XCodeFactory自动生成的数据层代码(二)
- C#分析数据库结构,使用XSL模板自动生成代码
- 简单代码的自动生成
- AutoThrCode 三层结构业务层代码自动生成工具
- Nhibernate开发代码工具,自动生成实体类、NHibernate的HBM映射文件和数据访问层的代码
- 代码自动生成工具的补充
- 利用xml自动生成j2ee代码
- 为什么要自动生成代码?
- UML工具推荐 Poseidon版本 可以免费下载,自动生成代码 C++ Java C# VB.NET等 (来自德国汉堡的国际性建模软件开发商Gentleware AG的)
- Hibernate中代码自动生成小结
- 代码自动生成和抽象
- 如何高效地使用XCodeFactory自动生成的数据层代码(一)
- access如何用代码在“默认值”里实现自动编号?单据流水号生成问题。
- 也论代码自动生成
- 根据一个大图片自动生成相应小图片的代码
- 强命名规范与代码自动生成工具
- 代码自动生成操作
- 代码自动生成.