Eclipse插件:MyBatis Generator代码自动生成工具

MyBatis Generator是一款优秀的工具,可以帮助我们自动生成java实体类,mapper接口和xml,极大得简化了开发流程,今天,就记录下在eclipse中使用eclipse插件集成MyBatis Generator的步骤;

【1:插件安装】Help--Eclipser Marketplace中查找:Mybatis Generator 1.3.5安装

安装好后,就可以在项目中使用MyBatis Generator了;

【2:创建generatorConfig.xml】右键—New—Other—MyBatis—MyBatis Generator Configuration File

【3.设置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>

	<!-- 数据库驱动jar路径 -->
	<classPathEntry location="C:\Users\acer\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar"/>
	
	<context id="context1">
	
		<!-- 1:注释构建;type-可通过实现CommentGenerator接口构建自定义的注释构建类 -->
		<commentGenerator type="">
			<!-- 是否去除自动生成的注释;true:是;false:否 -->
			<property name="suppressAllComments" value="false" />
		</commentGenerator>

		<!-- 2:数据库连接信息 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/risk" userId="root" password="root">
		</jdbcConnection>
		
		<!-- 3:生成实体类地址 -->
		<javaModelGenerator targetPackage="com.mybatis.generator" targetProject="generator"></javaModelGenerator>
	
		<!-- 4.生成map.xml地址 -->		
		<sqlMapGenerator targetPackage="com.mybatis.generator" targetProject="generator"></sqlMapGenerator>

		<!-- 5.生成DAO地址 -->
		<javaClientGenerator targetPackage="com.mybatis.generator" type="XMLMAPPER" targetProject="generator"></javaClientGenerator>
		
		<!-- 配置表信息 -->
		<table tableName="user"></table>
	</context>
</generatorConfiguration>

【4.自动生成代码】选中generatorConfig.xml—右键—Run As—Run MyBatis Generator

【5.代码自动生成】在配置文件设置好的目录下面,查看自动生成的文件

猜你喜欢

转载自blog.csdn.net/weixin_42601042/article/details/82353140