運行generateconfig.xml文件自動生成代碼的第4種方式.


前三種方式轉載

可愛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改名字也無所謂的.只要內容是對的就行.

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM