MyBatis-Generator自动生成基本代码


一,MyEclipse中安装Generator


          可以在MyEclipse中,选择install from site:http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/

   

         

         

二,生成各层类


   在src目录下,添加生成的配置文件:


 


 

<?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="H:\mysql-connector-java-5.1.7-bin.jar" /><!--配置绝对路径 -->

	<!-- 配置数据源连接 -->
	<context id="aisSnsTables" targetRuntime="Ibatis2Java5">
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/mybatis" userId="root"
			password="">
		</jdbcConnection>

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

		<!-- targetPackage:生成的pojo放入的包, targetProject:生成的pojo放入的项目(对应工作空间的项目) -->
		<javaModelGenerator targetPackage="ShuiTian.NaiLuo.po"
			targetProject="Shopping/src">
			<property name="enableSubPackages" value="false" />
			<property name="trimStrings" value="false" />
		</javaModelGenerator>

		<!--targetPackage=生成的sql对应的包 targetProject:生成的sql接口对应的项目 -->
		<sqlMapGenerator targetPackage="ShuiTian.NaiLuo.mapper"
			targetProject="Shopping/src">
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>

		<!-- targetPackage:生成的dao接口对应的包 targetProject:生成的dao接口对应的项目 type:映射文件类型,一般为XMLMAPPER -->
		<javaClientGenerator type="SPRING"
			targetPackage="ShuiTian.NaiLuo.service.impl" implementationPackage="ShuiTian.NaiLuo.service.impl"
			targetProject="Shopping/src">
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>

		<!-- 要生成哪些表 -->
		<table tableName="items" domainObjectName="Items" enableInsert="true"
			enableSelectByPrimaryKey="true" enableUpdateByPrimaryKey="true"
			enableDeleteByPrimaryKey="true" enableSelectByExample="false"
			enableDeleteByExample="false" enableCountByExample="false"
			enableUpdateByExample="false">
		</table>

		<table tableName="orderdetail" domainObjectName="Orderdetail"
			enableInsert="true" enableSelectByPrimaryKey="true"
			enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="true"
			enableSelectByExample="false" enableDeleteByExample="false"
			enableCountByExample="false" enableUpdateByExample="false">
		</table>

		<table tableName="orders" domainObjectName="Orders"
			enableInsert="true" enableSelectByPrimaryKey="true"
			enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="true"
			enableSelectByExample="false" enableDeleteByExample="false"
			enableCountByExample="false" enableUpdateByExample="false">
		</table>

		<table tableName="user" domainObjectName="User" enableInsert="true"
			enableSelectByPrimaryKey="true" enableUpdateByPrimaryKey="true"
			enableDeleteByPrimaryKey="true" enableSelectByExample="false"
			enableDeleteByExample="false" enableCountByExample="false"
			enableUpdateByExample="false">
		</table>

	</context>

</generatorConfiguration>


 之后在配置文件上右击:





ok~~~~~


三,配置文件的一些注意


           1,数据库的驱动包请配置成绝对路径,最好不要中文。

           2,困了=_=!




         


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水田如雅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值