欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Eclipse配置MyBatis代码自动化功能

程序员文章站 2022-03-05 19:19:19
...
1.安装插件
  Eclipse中,Help->Eclipse Marketplace,搜索MyBatis,
  安装一个扎红头绳小鸟的插件。

2.创建自动化配置文件generatorConfig.xml
  新建向导可找到模板,MyBatis->MyBatis Generator Configuration File,可得到一个带有主要配置不需求的模板,再根据自己的情况进行修改。如:
<?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="certTables">
  	<commentGenerator>
  		<property name="suppressAllComments" value="true"/>
  	</commentGenerator>
  	
    <jdbcConnection 
    	connectionURL="jdbc:mysql://127.0.0.1:3306/your_dbname?serverTimezone=Asia/Shanghai" 
    	driverClass="com.mysql.cj.jdbc.Driver" 
    	password="your_passward" 
    	userId="your_userid">
    </jdbcConnection>
    	
    <javaTypeResolver>
    	<property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>
    
    <javaModelGenerator targetPackage="com.wallimn.iteye.sp.asset.bus.cert.model" targetProject="asset">
    	<property name="enableSubPackages" value="false"/>
    	<property name="trimStrings" value="true"/>
    </javaModelGenerator>
    
    <sqlMapGenerator targetPackage="com.wallimn.iteye.sp.asset.bus.cert.model" targetProject="asset">
    	<property name="enableSubPackages" value="false"/>
    </sqlMapGenerator>
    
    <javaClientGenerator targetPackage="com.wallimn.iteye.sp.asset.bus.cert.dao" targetProject="asset" type="XMLMAPPER">
    	<property name="enableSubPackages" value="false"/>
    </javaClientGenerator>
    
     <table tableName="t_c_company"></table>
  </context>
</generatorConfiguration>


3.运行自动代码工具
  在配置文件上点右键,Run As,。。。

相关标签: eclipse mybatis