Mybatis-逆向工程实现
2017-11-06 16:49
525 查看
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="testTables" targetRuntime="MyBatis3"> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--数据库连接的信息:驱动类、连接地址、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/tiantian" userId="root" password="123456"> </jdbcConnection> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- targetProject:生成PO类的位置 --> <javaModelGenerator targetPackage="com.tian.pojo" targetProject=".\src\main\java"> <!-- enableSubPacka 4000 ges:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- targetProject:mapper映射文件生成的位置 --> <sqlMapGenerator targetPackage="com.tian.dao" targetProject=".\src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- targetPackage:mapper接口生成的位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.tian.dao" targetProject=".\src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 指定数据库表 --> <table tableName="tb_content" domainObjectName="Countent"></table> <table tableName="tb_content_category" domainObjectName="ContentCategory"></table> <table tableName="tb_item" domainObjectName="Item"></table> <table tableName="tb_item_cat" domainObjectName="ItemCat"></table> <table tableName="tb_item_desc" domainObjectName="ItemDesc"></table> <table tableName="tb_item_param" domainObjectName="ItemParam"></table> <table tableName="tb_item_param_item" domainObjectName="ItemParamItem"></table> <table tableName="tb_order" domainObjectName="Order"></table> <table tableName="tb_order_item" domainObjectName="OrderItem"></table> <table tableName="tb_order_shopping" domainObjectName="OrderShopping"></table> <table tableName="tb_user" domainObjectName="User"></table> </context> </generatorConfiguration>
执行程序
package com.tian.test; import java.io.File; import java.util.ArrayList; import java.util.List; import org.mybatis.generator.api.MyBatisGenerator; import org.mybatis.generator.config.Configuration; import org.mybatis.generator.config.xml.ConfigurationParser; import org.mybatis.generator.internal.DefaultShellCallback; public class GeneratorTest { public static void main(String[] args) throws Exception{ List<String>warnings=new ArrayList<>(); //1、获取配置文件 Configuration configuration=new ConfigurationParser(warnings). parseConfiguration(new File("src/main/resources/generatorConfig.xml")); //2、创建回调接口的实现类 DefaultShellCallback callback=new DefaultShellCallback(true); //3、创建生成器对象 MyBatisGenerator generator=new MyBatisGenerator(configuration, callback, warnings); //4、生成 generator.generate(null); } }
maven依赖
<!-- 逆向工程 --> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
相关文章推荐
- 用Intillij IDEA实现MyBatis逆向工程
- Mybatis逆向工程的pojo实现序列化接口代码
- Mybatis逆向工程的pojo实现序列化接口的代码
- mybatis的逆向工程使用实现
- Mybatis逆向工程的实现
- 用Maven中实现MyBatis逆向工程(IDEA版)
- 【JavaWeb_Part06】JDBC?弱爆了,来试试 MyBatis 的黑科技-逆向工程
- mybatis入门基础(九)----逆向工程
- MyBatis中使用逆向工程
- 第二招:Powerdesigner15-用jdbc链接MySQL实现逆向工程步骤
- mybatis generator(MyBatis的逆向工程)
- MyBatis(10)逆向工程
- 【MyBatis框架】mybatis逆向工程自动生成代码
- mybatis 逆向工程 用xml配置文件生成mapper和po的方法
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 从ruby实现时间服务器ntp同步功能也谈“逆向工程”
- Mybatis之逆向工程生成代码(mybatis generator)
- mybatis学习笔记(15)-mybatis逆向工程
- IDEA 中生成 MyBatis 逆向工程实践
- mybatis逆向工程出现XML Parser Error on line 1: 前言中不允许有内容。