前三种方式转载

可爱2014的博客

https://www.cnblogs.com/wangkeai/p/6934683.html

第四种方式是我认为最好用的.通过安装mybatis generator插件.

1.只需要下载mysql-connector-java-5.1.7-bin.jar包放置在电脑任意位置需要记住此位置,generateconfig.xml文件中需要用到.

2.然后在eclipse中通过help>>Eclipse Marketplace 搜索mybatis generator ,点击install安装,根据提示安装,期间会弹出此插件无认证,是否安装,点击安装.

3.安装成功后,重启eclipse,把generateconfig.xml文件放置在工程任意目录都可以.下面是generateconfig.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>
	<!-- 需要填写mysql-connector-java-5.1.7-bin.jar在电脑中的地址 -->
	<classPathEntry location="D:\software\jar\mysql-connector-java-5.1.7-bin.jar" />

	<context id="context1">
		<!-- 注释 -->
		<commentGenerator>
			<property name="suppressAllComments" value="true" /><!-- 是否取消注释 -->
			<property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳 -->
		</commentGenerator>
		<!-- 填写数据库信息 -->
		<jdbcConnection connectionURL="jdbc:mysql://localhost:3306/jingjiang"
			driverClass="com.mysql.jdbc.Driver" password="123456" userId="root" />


		<!-- 类型转换 -->
		<javaTypeResolver>
			<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<javaModelGenerator targetPackage="com.lei.chunlin.model"
			targetProject="springBoot/src/main/java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<sqlMapGenerator targetPackage="com.lei.chunlin.mapper"
			targetProject="springBoot/src/main/java">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>
		<javaClientGenerator targetPackage="com.lei.chunlin.mapper"
		targetProject="springBoot/src/main/java" type="XMLMAPPER" >
		<property name="enableSubPackages" value="true"/>
		</javaClientGenerator>

		<table schema="" tableName="scene" domainObjectName="Scene"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false" />
	</context>
</generatorConfiguration>

4.右击generateconfig.xml文件run as>>run mybatis generator,OK了.

5.此方法可以给generateconfig.xml改名字也无所谓的.只要内容是对的就行.

  

04-05 07:42