mybaits反向生成
1 首先创建一个springboot项目 pomx.xml中的内容在最下面
2 在resources下创建一个mybaits文件夹。文件下创建一个generatorConfig.xml。 再创建一个mappers包。 3 在java下创建mapper包和pojo 找到maven中的插件运行插件生成对应的文件 注意:看注释里面的数据库连接信息,实体类的地址,映射文件的地址和dao接口的地址,以及数据库表,这些都需要自己根据自己的环境和需求指定。
1 mysql数据库相关配置(mysql驱动包路径,数据库相关信息) 2 实体类生成位置(包,支持相对和绝对路径) 3 dao接口和映射文件的位置 4 指定数据库表,生成实体类和文件的名字
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>
<context id="localhost_mysql" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/taotao?characterEncoding=utf8&serverTimezone=UTC"
userId="root"
password="123456">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.taotao.pojo" targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="src/main/resources/mappers" targetProject=".">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.taotao.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table schema="" tableName="tb_content">
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_content_category">
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_item" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_item_cat" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_item_desc" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_item_param" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_item_param_item" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_order" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_order_item" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_order_shipping" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
<table schema="" tableName="tb_user" >
<generatedKey column="id" sqlStatement="mysql" identity="true" />
</table>
</context>
</generatorConfiguration>
pom.xml
<modelVersion>4.0.0
</modelVersion>
<parent>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-parent
</artifactId>
<version>2.3.1.RELEASE
</version>
<relativePath/>
</parent>
<groupId>com.itzz
</groupId>
<artifactId>taotao
</artifactId>
<version>0.0.1-SNAPSHOT
</version>
<name>taotao
</name>
<description>Demo project for Spring Boot
</description>
<properties>
<java.version>1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot
</groupId>
<artifactId>mybatis-spring-boot-starter
</artifactId>
<version>2.1.3
</version>
</dependency>
<dependency>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-devtools
</artifactId>
<scope>runtime
</scope>
<optional>true
</optional>
</dependency>
<dependency>
<groupId>mysql
</groupId>
<artifactId>mysql-connector-java
</artifactId>
<scope>compile
</scope>
</dependency>
<dependency>
<groupId>org.projectlombok
</groupId>
<artifactId>lombok
</artifactId>
<optional>true
</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-test
</artifactId>
<scope>test
</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage
</groupId>
<artifactId>junit-vintage-engine
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-maven-plugin
</artifactId>
<configuration>
<fork>true
</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator
</groupId>
<artifactId>mybatis-generator-maven-plugin
</artifactId>
<version>1.3.7
</version>
<executions>
<execution>
<id>Generate MyBatis Artifacts
</id>
<goals>
<goal>generate
</goal>
</goals>
</execution>
</executions>
<configuration>
<configurationFile>${basedir}/src/main/resources/mybatis/generatorConfig.xml
</configurationFile>
<includeCompileDependencies>true
</includeCompileDependencies>
<overwrite>true
</overwrite>
</configuration>
</plugin>
</plugins>
</build>