一、版本信息
- springboot:
2.6.15
- gradle:
6.9.4
- idea:
2024.1.1
- mybatis-generator:使用插件
gradle.plugin.com.arenagod.gradle:mybatis-- generator-plugin:1.4
- os:
macos
- DB:
postgresql
网上很多资料都是MySQL的配置方式,我配置DB是postgresql,可苦了我了…
二、配置文件
build.gradle
buildscript {
ext {
springBootVersion = '2.6.15'
}
repositories {
mavenCentral()
maven {
url 'https://maven.aliyun.com/repository/public/'
}
maven {
url 'https://maven.aliyun.com/repository/spring/'
}
//添加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'
//引入 mybatis-generator 插件
apply plugin: "com.arenagod.gradle.MybatisGenerator"
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
maven {
url 'https://maven.aliyun.com/repository/spring/'
}
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
//数据源
compile 'com.alibaba:druid-spring-boot-starter:1.1.2'
implementation 'org.postgresql:postgresql:42.7.3'
//配置mybatis
compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
//mybatis-generator core 包
compile group: 'org.mybatis.generator', name: 'mybatis-generator-core', version:'1.3.2'
}
configurations {
mybatisGenerator
}
// mybatis-generator.xml 配置路径
//这里会遇到个问题:MyBatis Generator 通过xml生成,有日志但是没有生成文件成功的问题,
//原因:mac下是找不到 ./src 路径的,需要全路径,如下配置。windows则为src/main/resources/generator.xml
mybatisGenerator {
verbose = true
//我这里是macOS,所以文件的路径一定要用全路径
configFile = '/Users/xiongzelin/项目/auth/src/main/resources/mybatis/mybatis-generator.xml'
}
mybatis-generator的代码生成配置文件
<?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>
<!-- generatorConfig.xml配置文件,放在resource目录下即可 -->
<classPathEntry location="/Users/xiongzelin/项目/auth/src/main/resources/mybatis/postgresql-42.3.1.jar"/>
<!--数据库驱动个人配置-->
<context id="MysqlTables" targetRuntime="MyBatis3">
<property name="autoDelimitKeywords" value="<