mybatis_generator自动生成 实体类,映射器,映射接口类

安装插件: help->install new sofeware 加入地址

name:generator

location:http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite

配置文件

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="E:/workspace2/SmartSign20140326/WebContent/WEB-INF/lib/mysql-connector-java-5.1.28-bin.jar" />

	<context id="context" targetRuntime="MyBatis3">
		<!-- 注释 -->
		<commentGenerator>
			<property name="suppressAllComments" value="true" />
			<property name="suppressDate" value="true" />
		</commentGenerator>

		<!-- 数据库连接 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://127.0.0.1:3306/SmartRoad" 
			userId="root" password="root" />

		<!--允许数值类型转换成不同类型,否则都映射为BigDecimal -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!-- 模型文件 -->
		<javaModelGenerator targetPackage="cn.tiger.smartsign.entity"
			targetProject="SmartSign20140326/src">
			<property name="enableSubPackages" value="false" />
			<!-- 当为true时,产生的代码文件将按照schema产生子文件夹 -->
			<property name="trimStrings" value="true" />
			<!-- set变量时自动剔除空白 -->
		</javaModelGenerator>

		<!-- XML映射文件 -->
		<sqlMapGenerator targetPackage="cn.tiger.smartsign.xml"
			targetProject="SmartSign20140326/src">
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>

		<!-- DAO文件(mapper接口) -->
		<javaClientGenerator targetPackage="cn.tiger.smartsign.dao"
			targetProject="SmartSign20140326/src" type="XMLMAPPER">
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>
<!-- 数据库表 -->
		<table schema="SmartRoad" tableName="users" domainObjectName="Users"
		    enableCountByExample="false" 
		    enableUpdateByExample="false"
			enableDeleteByExample="false"
			enableSelectByExample="false"
			selectByExampleQueryId="false"
		    >
			<property name="useActualColumnNames" value="false" />
		</table>
		
	</context>
</generatorConfiguration>

说明:

生成实体类配置

<!-- 模型文件 -->
		<javaModelGenerator targetPackage="cn.tiger.smartsign.entity"
			targetProject="SmartSign20140326/src">
			<property name="enableSubPackages" value="false" />
			<!-- 当为true时,产生的代码文件将按照schema产生子文件夹 -->
			<property name="trimStrings" value="true" />
			<!-- set变量时自动剔除空白 -->
		</javaModelGenerator>
生成映射器xml文件配置
<!-- 模型文件 -->
		<javaModelGenerator targetPackage="cn.tiger.smartsign.entity"
			targetProject="SmartSign20140326/src">
			<property name="enableSubPackages" value="false" />
			<!-- 当为true时,产生的代码文件将按照schema产生子文件夹 -->
			<property name="trimStrings" value="true" />
			<!-- set变量时自动剔除空白 -->
		</javaModelGenerator>



生成mapper接口

<!-- XML映射文件 -->
		<sqlMapGenerator targetPackage="cn.tiger.smartsign.xml"
			targetProject="SmartSign20140326/src">
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>

数据库表配置

<!-- 数据库表 -->
		<table schema="SmartRoad" tableName="users" domainObjectName="Users"
		    enableCountByExample="false" 
		    enableUpdateByExample="false"
			enableDeleteByExample="false"
			enableSelectByExample="false"
			selectByExampleQueryId="false"
		    >
			<property name="useActualColumnNames" value="false" />
		</table>

设置不生成Example类

enableCountByExample="false" 
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值