使用eclipse插件mybatis generator来生成文件代码

对于使用Mybatis的开发者来说, 使用mybatis generator来生成dao dto 以及配置文件, 可以大大简化工作, mybatis generator有多种工作方式, eclipse插件是一种比较友好的方式.


首先到http://blog.mybatis.org/p/products.html , 可以找到在线安装的地址


在线安装地址为 http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/


安装完毕之后,新建generatorConfig.xml, 用来控制文件生成



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="D:\maven\repository\org\postgresql\postgresql\9.3-1103-jdbc41\postgresql-9.3-1103-jdbc41.jar" />
	<context id="context1">
		<commentGenerator>
			<property name="suppressAllComments" value="true" /><!-- 是否取消注释 -->
			<property name="suppressDate" value="false" /> <!-- 是否生成注释代时间戳 -->
		</commentGenerator>
		<jdbcConnection driverClass="org.postgresql.Driver"
			connectionURL="jdbc:postgresql://192.168.1.1:14132/dev" userId="userId"
			password="password" />
			
		<!-- targetPackage是目标包名,  targetProject是包所在的位置-->
		<!-- javaModelGenerator生成的是实体类,  sqlMapGenerator生成的是映射文件,  javaClientGenerator生成的是dao -->
		<javaModelGenerator targetPackage="auto.dto"
			targetProject="testProject\src\main\java" />
		<sqlMapGenerator targetPackage="auto.xml"
			targetProject="testProject\src\main\java" />
		<javaClientGenerator targetPackage="auto.dao"
			targetProject="testProject\src\main\java" type="XMLMAPPER" />
			
		<!-- domainObjectName是表对应的实体类名,  tableName是对应的表名-->
		<!-- table可以配置多个,enable*几个参数是为了自动生成一些额外的sql操作,可以关闭-->
		<table domainObjectName="StudentInfoDto" tableName="student_info"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false">
		</table>
		<table domainObjectName="TeacherInfoDto" tableName="teacher_info"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false">
		</table>
	</context>
</generatorConfiguration>


然后右击文件, 选择Generate Mybatis Artifacts 即可.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值