mybatis逆向生成代码工具类

工具类:放到工具类文件中

public class Generator {

	 public void generator() throws Exception{  
	        List<String> warnings = new ArrayList<String>();  
	        boolean overwrite = true;  
	        File configFile = new File("mgb.xml");   
	        ConfigurationParser cp = new ConfigurationParser(warnings);  
	        Configuration config = cp.parseConfiguration(configFile);  
	        DefaultShellCallback callback = new DefaultShellCallback(overwrite);  
	        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,  
	                callback, warnings);  
	        myBatisGenerator.generate(null);  
	    }  
	 
	 public static void main(String[] args) throws Exception {  
	     try {  
	            Generator generatorSqlmap = new Generator();  
	            generatorSqlmap.generator();  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
		 
		
	}
}

xml文件:与pom文件放一起

<?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="DB2Tables" targetRuntime="MyBatis3" defaultModelType="flat">
  	
  	<!-- 配置生成的文件都没有注释 -->
  	<commentGenerator>
  		<property name="suppressAllComments" value="true" />
  	</commentGenerator>
  	<!-- 配置数据源 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
        connectionURL="jdbc:mysql://192.168.0.113/rce"
        userId="root"
        password="ROOT">
    </jdbcConnection>
	
    <javaTypeResolver>
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
	
	<!-- 配置javaBean生成的位置-->
    <javaModelGenerator targetPackage="com.wangyun.vo" targetProject=".\src\main\java">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>

	<!-- 配置sql映射文件生成的位置mapper -->
    <sqlMapGenerator targetPackage="com.wangyun.mapper"  targetProject=".\src\main\java">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
	
	<!-- 配置指定mapper接口生成的位置 -->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.wangyun.dao"  targetProject=".\src\main\java">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>

	<!-- table指定每个表的生成策略 -->
	<!-- tableName:对应的表      domainObjectName:生成的bean实例对象 -->
    <!-- <table tableName="users" domainObjectName="Users" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
	<table tableName="dlcenter" domainObjectName="Dlcenter" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> 
		<table tableName="cparameter" domainObjectName="Cparameter" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>-->
		<!-- <table tableName="job" domainObjectName="Job" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> -->
		<!-- <table tableName="power" domainObjectName="Power" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> -->
		
<!-- 		<table tableName="yearcontrol" domainObjectName="Yearcontrol" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> -->
		<table tableName="sysnotice" domainObjectName="Sysnotice" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
  </context>
</generatorConfiguration>

引入jar包

<!-- mybatis逆向工程包 -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值