转载

项目中3步解决Mybatis在桌面生成代码

数据库表有几张表复制几个<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…

原文  https://juejin.im/post/5cc6fa0751882564113f28cd
正文到此结束
Loading...