Mybatis 代码自动生成

使用 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>
	<!-- <properties resource="generatorConfig.properties" /> -->

	<classPathEntry location="F:/repository/mysql/mysql-connector-java/5.1.24/mysql-connector-java-5.1.24.jar" />

	<context id="XATL" targetRuntime="MyBatis3" defaultModelType="conditional">
		<!-- <plugin type="plugin.SelectByPagePlugin" /> -->
		<!-- 此处是将Example改名为Criteria 当然 想改成什么都行~ <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin"> <property name="searchString" 
			value="Example$" /> <property name="replaceString" value="Criteria" /> </plugin> <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" 
			/> <plugin type="org.mybatis.generator.plugins.MapperConfigPlugin"> <property name="fileName" value="GeneratedMapperConfig.xml" /> 
			<property name="targetPackage" value="com.cy.mybatis.mbg.util" /> <property name="targetProject" value="${targetProject}" /> </plugin> -->
		<commentGenerator>
			<!-- 去除自动生成的注释 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/xatl?generateSimpleParameterMetadata=true"
			userId="root" password="123456">
		</jdbcConnection>

		<javaTypeResolver>
			<property name="forceBigDecimals" value="true" />
		</javaTypeResolver>

		<!-- targetProject:自动生成代码的位置 -->
		<javaModelGenerator targetPackage="com.tianlong.entity" targetProject="D:\workspace\tianlong\src\main\java">
			<property name="enableSubPackages" value="true" />
		</javaModelGenerator>

		<sqlMapGenerator targetPackage="com.tianlong.dao" targetProject="D:\workspace\tianlong\src\main\java">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>

		<javaClientGenerator type="XMLMAPPER" targetPackage="com.tianlong.dao" targetProject="D:\workspace\tianlong\src\main\java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
		<!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
		<table tableName="account_cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="count_server_info" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="server_sects" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="skill_type" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="system_announcement" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="user_account" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_card_quality_experience" enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_cart_quality" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_consumables" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_experience" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_experience_consumables" enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_level_card" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_sects" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_server" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_skill" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="xa_type_card" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
			enableSelectByExample="false" selectByExampleQueryId="false"></table>
	</context>
</generatorConfiguration>

使用Maven 作为执行工具

添加插件 并且运行

  • mybatis-generator:generate (在Eclipse Maven插件运行失败)
<plugin>
	<groupId>org.mybatis.generator</groupId>
	<artifactId>mybatis-generator-maven-plugin</artifactId>
	<version>1.3.1</version>
	<configuration>
		<verbose>true</verbose>
		<overwrite>true</overwrite>
	</configuration>
</plugin>
详细参考官方:  http://mybatis.github.io/generator/

你可能感兴趣的:(Mybatis 代码自动生成)