mybatis自动生成工具

本文参考:http://www.mybatis.org/generator/index.html

利用mybatis自动生成工具来生成基本的JavaBean 以及 mapper文件以及dao

需要jar包:


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:/sharepackage/mysql-connector-java-5.1.41-bin.jar" />
	<!-- 一个数据库一个context  targetRuntime是指定生成代码的运行时目标  -->
	<!-- MyBatis3是默认值 使用该值,MBG将生成与MyBatis 3.0及更高版本以及JSE 5.0及更高版本兼容的对象-->
	<context id="DB2Tables" targetRuntime="MyBatis3">
		<!-- 定义注释生成器的属性 -->
		<commentGenerator>
			<!-- 是否生成带注释的时间戳 -->
			<property name="suppressDate" value="true" />
			<!-- 是否去除自动生成的注释 true:是 : false:否 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!--数据库链接URL,用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/test" userId="liujd"
			password="1234">
		</jdbcConnection>
		<!-- 用于定义java类型解析器的属性 用于从数据库列信息计算java类型  -->
		<javaTypeResolver>
			<!-- 是否强制对decimal和number字段使用java.math.BigDecimal -->
			<property name="forceBigDecimals" value="true" />
		</javaTypeResolver>
		<!-- 生成模型的包名和位置 -->
		<javaModelGenerator targetPackage="com.model"
			targetProject="arithmetic">
			<!-- 是否在当前路径下新加一层schema -->
			<property name="enableSubPackages" value="true" />
			<!-- 是否去除从数据库查出的数据两端的空格 -->
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!-- 生成映射文件的包名和位置 -->
		<sqlMapGenerator targetPackage="com.mapper"
			targetProject="arithmetic">
			<!-- 是否在当前路径下新加一层schema -->
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>
		<!-- 生成DAO的包名和位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.dao" targetProject="arithmetic">
			<!-- 是否在当前路径下新加一层schema -->
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
		<!-- 要生成哪些表 -->
		<table tableName="student" domainObjectName="student"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false">
			<generatedKey column="id" sqlStatement="JDBC" identity="true" />
		<!-- domainObjectName将生成的对象名 其他表示是否生成一个Example类 -->
		</table>

	</context>
</generatorConfiguration> 

利用eclipse运行:

右击配置文件 然后点击如下选项就可



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值