zoukankan      html  css  js  c++  java
  • springboot gradle配置(mybatis + mybatis-generator)

     1 buildscript {
     2     ext {
     3         springBootVersion = '2.3.4.RELEASE'
     4     }
     5     repositories {
     6         maven{ url "https://plugins.gradle.org/m2/"}
     7     }
     8 
     9     dependencies {
    10         classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    11         // mybatis-generator 插件路径
    12         classpath "gradle.plugin.com.arenagod.gradle:mybatis-generator-plugin:1.4"
    13     }
    14 }
    15 
    16 plugins {
    17     id 'org.springframework.boot' version '2.3.4.RELEASE'
    18     id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    19     id 'java'
    20     id "com.arenagod.gradle.MybatisGenerator" version "1.4"
    21 }
    22 
    23 apply plugin: "com.arenagod.gradle.MybatisGenerator"
    24 
    25 group = 'com.example'
    26 version = '0.0.1-SNAPSHOT'
    27 sourceCompatibility = '8'
    28 
    29 repositories {
    30 //    mavenCentral()
    31     maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    32 }
    33 
    34 allprojects {
    35     /**
    36      * Workaround intellij IDEA bug
    37      */
    38     apply plugin: 'idea'
    39     idea {
    40         module {
    41             inheritOutputDirs = true
    42         }
    43     }
    44 }
    45 
    46 configurations {
    47     mybatisGenerator
    48 }
    49 
    50 mybatisGenerator {
    51     verbose = true
    52     configFile = 'src/main/resources/mybatis/generatorConfig.xml'
    53 }
    54 
    55 dependencies {
    56     implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    57     implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    58     implementation 'org.springframework.boot:spring-boot-starter-web'
    59 //    implementation 'org.springframework.session:spring-session-jdbc'
    60     developmentOnly 'org.springframework.boot:spring-boot-devtools'
    61     compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.21'
    62     testImplementation('org.springframework.boot:spring-boot-starter-test') {
    63         exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    64     }
    65 
    66 //    compile group: 'com.alibaba', name: 'druid', version: '1.1.24'
    67     compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '2.1.3'
    68     developmentOnly group: 'org.mybatis.generator', name: 'mybatis-generator-core', version: '1.4.0'
    69 }
    70 
    71 jar {
    72     String classPath = ''
    73     configurations.runtime.each {classPath = classPath + " lib/"+it.name}
    74     manifest {
    75         attributes 'Main-Class': 'com.example.demo.DemoApplication'
    76         attributes 'Class-Path': classPath
    77     }
    78 }
    79 
    80 task copyJar(type:Copy){
    81     from configurations.runtime
    82     into ('build/libs/lib')
    83 }
    84 
    85 task release(type: Copy,dependsOn: [build, copyJar]) {
    86 }
    87 
    88 test {
    89     useJUnitPlatform()
    90 }

    resource 下放置generatorConfig.xml按照上面的路径放置: src/main/resources/mybatis/generatorConfig.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!DOCTYPE generatorConfiguration
     3         PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
     4         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
     5 <generatorConfiguration>
     6     <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
     7         <commentGenerator>
     8             <property name="suppressAllComments" value="true"></property>
     9             <property name="suppressDate" value="true"></property>
    10             <property name="javaFileEncoding" value="utf-8"/>
    11         </commentGenerator>
    12 
    13         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
    14                         connectionURL="jdbc:mysql://localhost:3306/db_demo_0"
    15                         userId="root"
    16                         password="root">
    17         </jdbcConnection>
    18 
    19         <javaTypeResolver>
    20             <property name="forceBigDecimals" value="false"/>
    21         </javaTypeResolver>
    22 
    23         <javaModelGenerator targetPackage="com.example.demo.model" targetProject="D:/Tools/demo/src/main/java">
    24             <property name="enableSubPackages" value="true"></property>
    25             <property name="trimStrings" value="true"></property>
    26         </javaModelGenerator>
    27 
    28         <sqlMapGenerator targetPackage="com.example.demo.mapper" targetProject="D:/Tools/demo/src/main/java">
    29             <property name="enableSubPackages" value="false"></property>
    30         </sqlMapGenerator>
    31 
    32         <javaClientGenerator targetPackage="com.example.demo.dao" targetProject="D:/Tools/demo/src/main/java" type="XMLMAPPER">
    33             <property name="enableSubPackages" value="false"/>
    34         </javaClientGenerator>
    35 
    36         <!-- sql占位符,表示所有的表 -->
    37         <table tableName="user_%">
    38         </table>
    39 
    40     </context>
    41 </generatorConfiguration>

    找到IDEA gradle Tasks -> other -> mbGenerator ,双击执行生成

  • 相关阅读:
    【Linux】VMware及VirtualBox网络配置
    【Linux】VirtualBox安装ubuntu排错LowGraphic
    【Hadoop】Win7上搭建Hadoop开发环境,方法一
    【JAVA】配置JAVA环境变量,安装Eclipse
    Eureka自我保护机制
    zookeeper代替eureka作为SpringCloud的服务注册中心
    mybatisplus代码生成器
    条件构造器 EntityWrapper (重要)
    idea 常用快捷键
    MybatisPlus的通用 CRUD
  • 原文地址:https://www.cnblogs.com/Joynic/p/13755907.html
Copyright © 2011-2022 走看看