废话不多说,
总共需要配置修改两个文件 项目地址 :
链接:https://pan.baidu.com/s/1UCKpOtpwH18NNvuLSL5cXQ
提取码:usoq
build.gradle文件:
buildscript { ext { springBootVersion = '2.1.1.RELEASE' } repositories { mavenCentral() //添加maven仓库 maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") // mybatis-generator 插件路径 classpath "gradle.plugin.com.arenagod.gradle:mybatis-generator-plugin:1.4" } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' //引入 mybatis-generator 插件 apply plugin: "com.arenagod.gradle.MybatisGenerator" group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { implementation('org.springframework.boot:spring-boot-starter-jdbc') implementation('org.springframework.boot:spring-boot-starter-web') runtimeOnly('mysql:mysql-connector-java') testImplementation('org.springframework.boot:spring-boot-starter-test') //mybatis-generator core 包 compile group: 'org.mybatis.generator', name: 'mybatis-generator-core', version:'1.3.2' } //generator.xml文件路径 mybatisGenerator { verbose = true //这里最好写绝对路径 configFile = 'D:\\workSpace\\springboot2\\src\\main\\resources\\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> <!-- 数据库驱动 --> <!--<classPathEntry--> <!--location="mysql-connector-java-5.1.38.jar" />--> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true" /> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--数据库链接URL,用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mytest" userId="root" password="123456"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.demo.entity" targetProject="D:\workSpace\springboot2\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成映射文件的包名和位置 --> <sqlMapGenerator targetPackage="mapper" targetProject="D:\workSpace\springboot2\src\main\resources"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成的Mapper接口的路径 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.demo.dao" targetProject="D:\workSpace\springboot2\src\main\java"> <property name="enableSubPackages" value="true"/> <property name="rootClass" value="com.demo.mapper.common.BaseMapper"/> </javaClientGenerator> <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名 --> <table tableName="t_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
---------------------------------------------持之以恒