Springboot mybatis generate 自动生成实体类和Mapper

幼敏悟过人,读书辄成诵。这篇文章主要讲述Springboot mybatis generate 自动生成实体类和Mapper相关的知识,希望能为你提供帮助。
maven项目
pom.xml

< ?xml version="1.0" encoding="UTF-8"?> < 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> < parent> < groupId> org.springframework.boot< /groupId> < artifactId> spring-boot-starter-parent< /artifactId> < version> 2.1.3.RELEASE< /version> < relativePath/> < !-- lookup parent from repository --> < /parent> < groupId> com.example< /groupId> < artifactId> demo< /artifactId> < version> 0.0.1-SNAPSHOT< /version> < name> demo< /name> < description> Demo project for Spring Boot< /description> < properties> < java.version> 1.8< /java.version> < /properties> < build> < plugins> < plugin> < !--Mybatis-generator插件,用于自动生成Mapper和POJO--> < groupId> org.mybatis.generator< /groupId> < artifactId> mybatis-generator-maven-plugin< /artifactId> < version> 1.3.5< /version> < configuration> < configurationFile> src/main/resources/generatorConfig.xml< /configurationFile> < verbose> true< /verbose> < overwrite> true< /overwrite> < /configuration> < executions> < execution> < id> Generate MyBatis Artifacts< /id> < goals> < goal> generate< /goal> < /goals> < /execution> < /executions> < /plugin> < /plugins> < /build> < dependencies> < dependency> < groupId> org.springframework.boot< /groupId> < artifactId> spring-boot-starter-freemarker< /artifactId> < /dependency> < 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.0.0< /version> < /dependency> < dependency> < groupId> mysql< /groupId> < artifactId> mysql-connector-java< /artifactId> < scope> runtime< /scope> < /dependency> < dependency> < groupId> org.springframework.boot< /groupId> < artifactId> spring-boot-starter-test< /artifactId> < scope> test< /scope> < /dependency> < !--aop支持--> < dependency> < groupId> org.springframework.boot< /groupId> < artifactId> spring-boot-starter-aop< /artifactId> < /dependency> < !--swagger--> < dependency> < groupId> io.springfox< /groupId> < artifactId> springfox-swagger2< /artifactId> < version> 2.7.0< /version> < /dependency> < dependency> < groupId> io.springfox< /groupId> < artifactId> springfox-swagger-ui< /artifactId> < version> 2.7.0< /version> < /dependency> < /dependencies> < /project>

注意generatorConfig.xml的路径
下面是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> < !-- 本地数据库驱动程序jar包的全路径 --> < classPathEntry location="C:/mysql-connector-java-8.0.15.jar"/> < context id="context" targetRuntime="MyBatis3"> < commentGenerator> < property name="suppressAllComments" value="https://www.songbingjia.com/android/false"/> < property name="suppressDate" value="https://www.songbingjia.com/android/true"/> < /commentGenerator> < !-- 数据库的相关配置 --> < jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/dtpt?serverTimezone=UTC" userId="rong" password="123456"/> < javaTypeResolver> < property name="forceBigDecimals" value="https://www.songbingjia.com/android/false"/> < /javaTypeResolver> < !-- 实体类生成的位置 --> < javaModelGenerator targetPackage="com.example.pojo" targetProject="src/main/java"> < property name="enableSubPackages" value="https://www.songbingjia.com/android/false"/> < property name="trimStrings" value="https://www.songbingjia.com/android/true"/> < /javaModelGenerator> < !-- *Mapper.xml 文件的位置 --> < sqlMapGenerator targetPackage="mybatis" targetProject="src/main/java"> < property name="enableSubPackages" value="https://www.songbingjia.com/android/false"/> < /sqlMapGenerator> < !-- Mapper 接口文件的位置 --> < javaClientGenerator targetPackage="com.example.mapper" targetProject="src/main/java" type="XMLMAPPER"> < property name="enableSubPackages" value="https://www.songbingjia.com/android/false"/> < /javaClientGenerator> < !-- 相关表的配置 --> < table tableName="t_user" domainObjectName="UserDTO" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/> < /context> < /generatorConfiguration>

  然后双击运行这个
Springboot mybatis generate 自动生成实体类和Mapper

文章图片

运行成功
Springboot mybatis generate 自动生成实体类和Mapper

文章图片

 
  ok
 
【Springboot mybatis generate 自动生成实体类和Mapper】结束

    推荐阅读