SpringBoot2.0整合Mybatis之逆向工程(eclipse环境)

下面这个图是逆向工程已生成好的,特此备忘!话不多说 上图!

一.项目结构

二.db.properties

#============================#
#===== Database sttings =====#
#============================#
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/smarthse?serverTimezone=Asia/Shanghai
jdbc.username=root
jdbc.password=root

 

三.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>  
    <!-- 引入配置文件 -->  
    <properties resource="db.properties"/>  
      
   <!-- 
   jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.188:3306/smarthse_platform?serverTimezone=Asia/Shanghai
jdbc.username=ehs-root2
jdbc.password=test1234567
    -->
    <!-- 一个数据库一个context -->  
    <context id="DB2Tables" targetRuntime="MyBatis3">
		<commentGenerator>
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!-- 配置数据库连接 -->
		<jdbcConnection driverClass="${jdbc.driver}"
			connectionURL="${jdbc.url}" userId="${jdbc.username}"
			password="${jdbc.password}">
		</jdbcConnection>

		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!-- 指定javaBean生成的位置 -->
		<javaModelGenerator targetPackage="com.example.bean"
			targetProject=".\src\main\java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<!--指定sql映射文件生成的位置 -->
		<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>

		<!-- 指定dao接口生成的位置,mapper接口 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.example.dao" targetProject=".\src\main\java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>


		<!-- table指定每个表的生成策略 -->
		<table tableName="agent_area" domainObjectName="AgentArea"></table>
		<table tableName="agent_user_login" domainObjectName="AgentUserLogin"></table>
		<table tableName="agent_soft_record" domainObjectName="AgentSoftRecord"></table>
		<table tableName="agent_user_login" domainObjectName="AgentUserLogin"></table>
		<table tableName="agent_balance" domainObjectName="AgentBalance"></table>
		<table tableName="agent_balance_detail" domainObjectName="AgentBalanceDetail"></table>
		<table tableName="agent_payment" domainObjectName="AgentPayment"></table>
		<table tableName="agent_business" domainObjectName="AgentBusiness"></table>
		<table tableName="agent_basic_info" domainObjectName="AgentBasicInfo"></table>
		
		<table tableName="agent_promo_code" domainObjectName="AgentPromoCode"></table>
	</context> 
</generatorConfiguration>  

 

四.pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>springboot_thymeleaf_web</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.4.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
 
	<properties>
		
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>
 
	<dependencies>
	
		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
 
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!--热启动 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency>
		
		<dependency>
		  <!-- jsoup html解析器 -->
		  <groupId>org.jsoup</groupId>
		  <artifactId>jsoup</artifactId>
		  <version>1.11.3</version>
		</dependency>
		<!-- thymeleaf依赖 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
 
 		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
		
		<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
		
		<dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.3</version>
        </dependency>
        
        <!-- SpringBoot - MyBatis -->
		<dependency>
		   <groupId>org.mybatis.spring.boot</groupId>
		   <artifactId>mybatis-spring-boot-starter</artifactId>
		   <version>1.3.1</version>
		</dependency>
	</dependencies>
 
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					 <source>1.8</source>
	                 <target>1.8</target>
					<!--热启动 -->
					<fork>true</fork>
				</configuration>
			</plugin>
			
			<plugin>
	          <groupId>org.mybatis.generator</groupId>
	          <artifactId>mybatis-generator-maven-plugin</artifactId>
	          <version>1.3.7</version>
	          <configuration>
                  <!--允许移动生成的文件 -->
			      <verbose>true</verbose>
			      <!-- 是否覆盖 -->
			      <overwrite>true</overwrite>
              </configuration>
               
	          <dependencies>
	          	<dependency>
		            <groupId>mysql</groupId>
		            <artifactId>mysql-connector-java</artifactId>
		            <version>5.1.30</version>
		         </dependency>
	          </dependencies>
	        </plugin>
		</plugins>
	</build>


	
</project>

 

五.一切准备就绪,接下来使用maven命令mybatis-generator:generate  打开run configuration 如图配置:

Run一下,生成成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值