專案中3步解決Mybatis在桌面生成程式碼

穿格子衣上班發表於2019-04-29

1.修改語句箭頭

資料庫表有幾張表複製幾個<table(這個很簡單照的步驟一步步來)

專案中3步解決Mybatis在桌面生成程式碼

<?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="mysql-connector-java-5.1.28.jar"/>
	<context id="DB2Tables"	targetRuntime="MyBatis3">
 <commentGenerator> 

                <property name="suppressAllComments" value="true" /> 

            </commentGenerator>  
		<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/vhr" userId="root" password="123456">
		</jdbcConnection>
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false"/>
		</javaTypeResolver>

		<javaModelGenerator targetPackage="org.javaboy.bean" targetProject="src">
			<property name="enableSubPackages" value="true"/>
			<property name="trimStrings" value="true"/>
		</javaModelGenerator>

		<sqlMapGenerator targetPackage="org.javaboy.mapper" targetProject="src">
			<property name="enableSubPackages" value="true"/>
		</sqlMapGenerator>

		<javaClientGenerator type="XMLMAPPER" targetPackage="org.javaboy.mapper" targetProject="src">
			<property name="enableSubPackages" value="true"/>
		</javaClientGenerator>

	     <table tableName="adjustsalary" domainObjectName="Adjustsalary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>

複製程式碼

2.run.bat開啟檔案生成src目錄程式碼

  • run.bat啟動無效,就刪掉建立一個.txt檔案,裡面寫下條命令儲存,修改檔案格式.bat
  • 生成沒程式碼看xml檔案資訊是否有錯
java -jar lib/mybatis-generator-core-1.3.1.jar -configfile generator.xml -overwrite
複製程式碼

專案中3步解決Mybatis在桌面生成程式碼

3.拷貝src目錄中程式碼到專案中

專案中3步解決Mybatis在桌面生成程式碼

4.pom.xml檔案中配依賴

  • 根據自己需求配置這很簡單的
   <dependency>
       <groupId>org.mybatis.spring.boot</groupId>
       <artifactId>mybatis-spring-boot-starter</artifactId>
       <version>2.0.1</version>
   </dependency>

   <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

複製程式碼

if4-my.sharepoint.com/:f:/g/perso…

首先下載檔案mybatis-generator-core-1.3.1解壓按照上面123步驟做實現(qq197467037)。

  • 檔案src裡的程式碼要清掉

相關文章