MyBatis-Generator自动生成基本代码

简介: 一,MyEclipse中安装Generator          可以在MyEclipse中,选择install from site:http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateS...


一,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,困了=_=!




         


目录
相关文章
|
30天前
|
Java 关系型数据库 数据库连接
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
26 1
|
1月前
|
XML Java 数据库连接
mybatis环境搭建步骤(含配置文件代码)
mybatis环境搭建步骤(含配置文件代码)
15 1
|
4月前
|
Oracle Java 数据库连接
使用Mybatis generator自动生成代码,仅限Oracle数据库
使用Mybatis generator自动生成代码,仅限Oracle数据库
|
4月前
|
XML Java 数据库连接
MybatisX快速生成代码(mybatis plus模板)
MybatisX快速生成代码(mybatis plus模板)
|
1月前
|
关系型数据库 Java 数据库连接
如何利用Mybatis-Plus自动生成代码(超详细注解)
如何利用Mybatis-Plus自动生成代码(超详细注解)
26 1
|
2月前
|
IDE Java 应用服务中间件
基于Spring+mybatis的SSM超市消费积分管理系统代码实现含演示站
这是一个SSM超市消费积分管理系统。有2个角色:买家角色和管理员角色,现在开始分角色介绍下功能。买家角色核心功能有买家登录,查看网站首页,查看蔬菜详情,加入购物车,提交订单,查看我的订单。管理员角色核心功能有管理员登录,用户管理,管理员管理,商品管理,一级分类管理,二级分类管理,订单管理。更多的功能可以去演示站查看。
基于Spring+mybatis的SSM超市消费积分管理系统代码实现含演示站
|
4月前
|
SQL Java 关系型数据库
【Spring Boot+Thymeleaf+MyBatis+mysql】实现电子商务平台实战(附源码)持续更新~~ 包括sql语句、java、html代码
【Spring Boot+Thymeleaf+MyBatis+mysql】实现电子商务平台实战(附源码)持续更新~~ 包括sql语句、java、html代码
50 0
|
4月前
|
Oracle Java 关系型数据库
mybatis快速自动生成代码【采用工具,开箱即用】
mybatis快速自动生成代码【采用工具,开箱即用】
|
4月前
|
Java 数据库连接 Maven
SSM复习之mybatis01:Mybatis简介-第一个Mybatis代码简单实现
SSM复习之mybatis01:Mybatis简介-第一个Mybatis代码简单实现
36 0
|
4月前
|
Apache
mybatis-plus代码方式配置
mybatis-plus代码方式配置
30 0