mybatis自动生成器(mybatis.generator)使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tidu2chengfo/article/details/77754738

我们在工程开发时经常会需要很多表,需要生成很多model对象,如果需要一个一个的写这些model和对应的映射文件及sql,是一件比较繁杂的事情。幸好,有现成的工具可以通过简单的配置,然后一键生成github地址 点击打开链接

下面展示一下使用方式

1,第一步下载eclipse插件

下载地址

2,创建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:/repo/mysql/mysql-connector-java/5.1.30/mysql-connector-java-5.1.30.jar" />
	<context id="context1">
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://***/**_db?" userId="***"
			password="***" />
		<javaModelGenerator targetPackage="com.halfworlders.idat.model"
			targetProject="idat-service" />
		<sqlMapGenerator targetPackage="com.halfworlders.idat.mapper" targetProject="idat-service" />
		<javaClientGenerator targetPackage="com.halfworlders.idat.dao"
			targetProject="idat-service" type="XMLMAPPER" />
		<table tableName="authorities">
		</table>
		<table tableName="groups">
		</table>
		<table tableName="group_authorities">
		</table>
		<table tableName="group_members">
		</table>
		<table tableName="users">
		</table>
	</context>
</generatorConfiguration>
以上:

工程名:idat-service

domain层包名:com.halfworlders.idat.model

dao层包名:com.halfworlders.idat.dao

mapper文件包名:com.halfworlders.idat.mapper

需要自动生成的表名:authorities,groups,group_authorities,group_members,users,具体表结构见前文 点击打开链接

3,将第1步下载的文件解压到eclipse文件夹内,本人用的eclipse版本Mars.2 Release (4.5.2)

4,重启eclipse,在generatorConfig.xml上右键单击选择generate Mybatis/ibatis Artifacts


即可自动生成需要的mapper文件,dao层接口,model对象

猜你喜欢

转载自blog.csdn.net/tidu2chengfo/article/details/77754738