├── .gitignore ├── .travis.yml ├── README.md ├── SpringBootCodeGenerator.iml ├── app.sh ├── codegenerator1.png ├── codegenerator2.png ├── codegenerator3.png ├── codegenerator4.png ├── donate.jpg ├── generator-web ├── generator-web.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── softdev │ │ └── system │ │ └── generator │ │ ├── GeneratorWebApplication.java │ │ ├── config │ │ ├── GlobalDefaultExceptionHandler.java │ │ ├── ServerConfig.java │ │ └── WebMvcConfig.java │ │ ├── controller │ │ └── IndexController.java │ │ ├── entity │ │ ├── ClassInfo.java │ │ ├── FieldInfo.java │ │ └── ReturnT.java │ │ └── util │ │ ├── ApiReturnObject.java │ │ ├── ApiReturnUtil.java │ │ ├── BasePath.java │ │ ├── CodeGenerateException.java │ │ ├── CodeGeneratorTool.java │ │ ├── FreemarkerTool.java │ │ ├── FreemarkerUtil.java │ │ ├── StringPlusUtils.java │ │ ├── StringUtils.java │ │ └── TableParseUtil.java │ └── resources │ ├── application.yml │ ├── favicon.ico │ └── templates │ ├── code-generator │ ├── beetlsql │ │ ├── beetlcontroller.ftl │ │ ├── beetlentity.ftl │ │ ├── beetlentitydto.ftl │ │ └── beetlmd.ftl │ ├── jdbc-template │ │ ├── jtdao.ftl │ │ └── jtdaoimpl.ftl │ ├── jpa-new │ │ ├── dto.ftl │ │ ├── entity.ftl │ │ ├── jpacontroller-old.ftl │ │ ├── jpacontroller.ftl │ │ ├── repository.ftl │ │ ├── service.ftl │ │ └── vo.ftl │ ├── jpa-rest-delete │ │ ├── dto.ftl │ │ ├── entity.ftl │ │ ├── jpacontroller-old.ftl │ │ ├── jpacontroller.ftl │ │ ├── repository.ftl │ │ ├── service.ftl │ │ └── vo.ftl │ ├── jpa-rest │ │ ├── addparam.ftl │ │ ├── dto.ftl │ │ ├── entity.ftl │ │ ├── jpacontroller-old.ftl │ │ ├── jpacontroller.ftl │ │ ├── pageparam.ftl │ │ ├── projection.ftl │ │ ├── repository.ftl │ │ ├── service.ftl │ │ ├── test.ftl │ │ ├── updateparam.ftl │ │ └── vo.ftl │ ├── jpa │ │ ├── entity.ftl │ │ ├── jpacontroller.ftl │ │ └── repository.ftl │ ├── mybatis-plus │ │ ├── pluscontroller.ftl │ │ └── plusmapper.ftl │ ├── mybatis │ │ ├── controller.ftl │ │ ├── mapper.ftl │ │ ├── model.ftl │ │ ├── mybatis.ftl │ │ ├── service.ftl │ │ └── service_impl.ftl │ ├── restful-jpa │ │ ├── entity.ftl │ │ ├── jpacontroller.ftl │ │ ├── repository.ftl │ │ └── service.ftl │ ├── ui │ │ ├── bootstrap-ui.ftl │ │ ├── element-ui.ftl │ │ └── swagger-ui.ftl │ └── util │ │ └── util.ftl │ ├── common │ └── common-import.ftl │ ├── index.ftl │ └── sql-generator │ └── pgsql │ ├── delete.ftl │ ├── drop.ftl │ ├── insert.ftl │ ├── select.ftl │ ├── sql.ftl │ └── update.ftl └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,maven,eclipse,java-web,intellij+all 3 | # Edit at https://www.gitignore.io/?templates=java,maven,eclipse,java-web,intellij+all 4 | 5 | ### Eclipse ### 6 | .metadata 7 | bin/ 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .settings/ 15 | .loadpath 16 | .recommenders 17 | 18 | # External tool builders 19 | .externalToolBuilders/ 20 | 21 | # Locally stored "Eclipse launch configurations" 22 | *.launch 23 | 24 | # PyDev specific (Python IDE for Eclipse) 25 | *.pydevproject 26 | 27 | # CDT-specific (C/C++ Development Tooling) 28 | .cproject 29 | 30 | # CDT- autotools 31 | .autotools 32 | 33 | # Java annotation processor (APT) 34 | .factorypath 35 | 36 | # PDT-specific (PHP Development Tools) 37 | .buildpath 38 | 39 | # sbteclipse plugin 40 | .target 41 | 42 | # Tern plugin 43 | .tern-project 44 | 45 | # TeXlipse plugin 46 | .texlipse 47 | 48 | # STS (Spring Tool Suite) 49 | .springBeans 50 | 51 | # Code Recommenders 52 | .recommenders/ 53 | 54 | # Annotation Processing 55 | .apt_generated/ 56 | 57 | # Scala IDE specific (Scala & Java development for Eclipse) 58 | .cache-main 59 | .scala_dependencies 60 | .worksheet 61 | 62 | ### Eclipse Patch ### 63 | # Eclipse Core 64 | .project 65 | 66 | # JDT-specific (Eclipse Java Development Tools) 67 | .classpath 68 | 69 | # Annotation Processing 70 | .apt_generated 71 | 72 | .sts4-cache/ 73 | 74 | ### Intellij+all ### 75 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 76 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 77 | 78 | # User-specific stuff 79 | .idea/**/workspace.xml 80 | .idea/**/tasks.xml 81 | .idea/**/usage.statistics.xml 82 | .idea/**/dictionaries 83 | .idea/**/shelf 84 | 85 | # Generated files 86 | .idea/**/contentModel.xml 87 | 88 | # Sensitive or high-churn files 89 | .idea/**/dataSources/ 90 | .idea/**/dataSources.ids 91 | .idea/**/dataSources.local.xml 92 | .idea/**/sqlDataSources.xml 93 | .idea/**/dynamic.xml 94 | .idea/**/uiDesigner.xml 95 | .idea/**/dbnavigator.xml 96 | 97 | # Gradle 98 | .idea/**/gradle.xml 99 | .idea/**/libraries 100 | 101 | # Gradle and Maven with auto-import 102 | # When using Gradle or Maven with auto-import, you should exclude module files, 103 | # since they will be recreated, and may cause churn. Uncomment if using 104 | # auto-import. 105 | # .idea/modules.xml 106 | # .idea/*.iml 107 | # .idea/modules 108 | 109 | # CMake 110 | cmake-build-*/ 111 | 112 | # Mongo Explorer plugin 113 | .idea/**/mongoSettings.xml 114 | 115 | # File-based project format 116 | *.iws 117 | 118 | # IntelliJ 119 | out/ 120 | 121 | # mpeltonen/sbt-idea plugin 122 | .idea_modules/ 123 | 124 | # JIRA plugin 125 | atlassian-ide-plugin.xml 126 | 127 | # Cursive Clojure plugin 128 | .idea/replstate.xml 129 | 130 | # Crashlytics plugin (for Android Studio and IntelliJ) 131 | com_crashlytics_export_strings.xml 132 | crashlytics.properties 133 | crashlytics-build.properties 134 | fabric.properties 135 | 136 | # Editor-based Rest Client 137 | .idea/httpRequests 138 | 139 | # Android studio 3.1+ serialized cache file 140 | .idea/caches/build_file_checksums.ser 141 | 142 | # JetBrains templates 143 | **___jb_tmp___ 144 | 145 | ### Intellij+all Patch ### 146 | # Ignores the whole .idea folder and all .iml files 147 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 148 | 149 | .idea/ 150 | 151 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 152 | 153 | *.iml 154 | modules.xml 155 | .idea/misc.xml 156 | *.ipr 157 | 158 | # Sonarlint plugin 159 | .idea/sonarlint 160 | 161 | ### Java ### 162 | # Compiled class file 163 | *.class 164 | 165 | # Log file 166 | *.log 167 | 168 | # BlueJ files 169 | *.ctxt 170 | 171 | # Mobile Tools for Java (J2ME) 172 | .mtj.tmp/ 173 | 174 | # Package Files # 175 | *.jar 176 | *.war 177 | *.nar 178 | *.ear 179 | *.zip 180 | *.tar.gz 181 | *.rar 182 | 183 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 184 | hs_err_pid* 185 | 186 | ### Java-Web ### 187 | ## ignoring target file 188 | target/ 189 | 190 | ### Maven ### 191 | pom.xml.tag 192 | pom.xml.releaseBackup 193 | pom.xml.versionsBackup 194 | pom.xml.next 195 | release.properties 196 | dependency-reduced-pom.xml 197 | buildNumber.properties 198 | .mvn/timing.properties 199 | .mvn/wrapper/maven-wrapper.jar 200 | 201 | # End of https://www.gitignore.io/api/java,maven,eclipse,java-web,intellij+all -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringBootCodeGenerator 2 | 3 | ![image](https://img.shields.io/badge/SpringBoot2-%E2%98%85%E2%98%85%E2%98%85%E2%98%85%E2%98%85-brightgreen.svg) 4 | ![image](https://img.shields.io/badge/Freemarker-%E2%98%85%E2%98%85%E2%98%85%E2%98%85%E2%98%85-brightgreen.svg) 5 | ![image](https://img.shields.io/badge/CodeGenerator-%E2%98%85%E2%98%85%E2%98%85%E2%98%85%E2%98%85-brightgreen.svg) 6 | [![Build Status](https://travis-ci.org/moshowgame/SpringBootCodeGenerator.svg?branch=master)](https://travis-ci.org/moshowgame/SpringBootCodeGenerator) 7 | 8 | > 原项目地址 [SpringBootCodeGenerator](https://github.com/moshowgame/SpringBootCodeGenerator) 9 | > 在此基础上进行了一些修改 10 | 11 | ### 项目介绍 12 | 13 | 基于SpringBoot2+Freemarker的代码生成器,用DDL SQL语句生成JPA/JdbcTemplate/Mybatis/BeetlSQL相关代码,支持mysql/oracle/pgsql等三大数据库。以释放双手为目的。 14 | 15 | 16 | 17 | 18 | 19 | 20 |
访问路径 http://127.0.0.1:1234/generator
在线地址 http://java.bejson.com/generator
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
字段名 说明
packageName 自定义的包名
authorName 自定义的作者名
returnUtil 自定义的返回Util
tableName sql中的表名
className java类名
classComment sql表备注/java类备注
fieldName 字段名
fieldComment 字段备注
31 | 32 | ### 运行效果 33 | 34 | **首页** 35 | 36 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190524200756.png) 37 | 38 | ### 添加功能 39 | 40 | #### JPA-NEW(将JPA修改为适合自己项目的模板) 41 | 42 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190707211702.png) 43 | 44 | #### jpa rest (2019-8-27) 45 | 46 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190827105024.png) 47 | 48 | #### bean get set 49 | 50 | 项目中经常会遇到需要 get bean 所有属性和 set bean 所有属性的情况,添加此功能方便开发 51 | 52 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190707212234.png) 53 | 54 | #### SQL 55 | 56 | 使用Navicat 通常需要写select、insert、update、delete语句,比较麻烦,使用此功能只需要填充数据即可使用 57 | 58 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190707212624.png) 59 | 60 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190707212703.png) 61 | 62 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190707212728.png) 63 | 64 | ![](https://raw.githubusercontent.com/gaohanghang/images/master/img20190707212756.png) 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /SpringBootCodeGenerator.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /app.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## blog:www.cnbuilder.cn 3 | ## create 2019-04-30 4 | version="5.2.1"; 5 | appName=$2 6 | if [ -z $appName ];then 7 | appName=`ls -t |grep .jar$ |head -n1` 8 | fi 9 | ## 后台启动项目 自动生成 catalina.log日志文件 10 | function start() 11 | { 12 | count=`ps -ef |grep java|grep $appName|wc -l` 13 | if [ $count != 0 ];then 14 | echo "Maybe $appName is running, please check it..." 15 | else 16 | echo "The $appName is starting..." 17 | ulimit -c unlimited 18 | nohup java -jar ./$appName -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512M -Xmx4G > catalina.log 2>&1 & 19 | fi 20 | } 21 | ## 停止项目 22 | function stop() 23 | { 24 | appId=`ps -ef |grep java|grep $appName|awk '{print $2}'` 25 | if [ -z $appId ];then 26 | echo "Maybe $appName not running, please check it..." 27 | else 28 | echo "The $appName is stopping..." 29 | kill -9 $appId 30 | fi 31 | } 32 | ##重启项目(平滑启动) 33 | function restart() 34 | { 35 | # get release version 36 | releaseApp=`ls -t |grep .jar$ |head -n1` 37 | # get last version 38 | lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1` 39 | appName=$lastVersionApp 40 | stop 41 | for i in {5..1} 42 | do 43 | echo -n "$i " 44 | sleep 1 45 | done 46 | echo 0 47 | backup 48 | appName=$releaseApp 49 | start 50 | } 51 | function backup() 52 | { 53 | # get backup version 54 | backupApp=`ls |grep -wv $releaseApp$ |grep .jar$` 55 | # create backup dir 56 | if [ ! -d "backup" ];then 57 | mkdir backup 58 | fi 59 | # backup 60 | for i in ${backupApp[@]} 61 | do 62 | echo "backup" $i 63 | mv $i backup 64 | done 65 | } 66 | ## 查看项目当前状态 67 | function status() 68 | { 69 | appId=`ps -ef |grep java|grep $appName|awk '{print $2}'` 70 | if [ -z $appId ] 71 | then 72 | echo -e "\033[31m Not running \033[0m" 73 | else 74 | echo -e "\033[32m Running [$appId] \033[0m" 75 | fi 76 | } 77 | function usage() 78 | { 79 | echo "Usage: $0 {start|stop|restart|status|stop -f}" 80 | echo "Example: $0 start" 81 | exit 1 82 | } 83 | case $1 in 84 | start) 85 | start;; 86 | stop) 87 | stop;; 88 | restart) 89 | restart;; 90 | status) 91 | status;; 92 | *) 93 | usage;; 94 | esac 95 | -------------------------------------------------------------------------------- /codegenerator1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hacker-and-painter/spring-boot-code-generator/cad403fc56934b250da9be6afee59d3e70d06dcb/codegenerator1.png -------------------------------------------------------------------------------- /codegenerator2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hacker-and-painter/spring-boot-code-generator/cad403fc56934b250da9be6afee59d3e70d06dcb/codegenerator2.png -------------------------------------------------------------------------------- /codegenerator3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hacker-and-painter/spring-boot-code-generator/cad403fc56934b250da9be6afee59d3e70d06dcb/codegenerator3.png -------------------------------------------------------------------------------- /codegenerator4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hacker-and-painter/spring-boot-code-generator/cad403fc56934b250da9be6afee59d3e70d06dcb/codegenerator4.png -------------------------------------------------------------------------------- /donate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hacker-and-painter/spring-boot-code-generator/cad403fc56934b250da9be6afee59d3e70d06dcb/donate.jpg -------------------------------------------------------------------------------- /generator-web/generator-web.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /generator-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | com.softdev.system 9 | SpringBootCodeGenerator 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | com.softdev.system 14 | generator-web 15 | 0.0.1-SNAPSHOT 16 | jar 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 1.8 22 | 23 | 24 | 25 | 26 | 27 | 28 | 33 | 34 | 35 | 39 | 40 | 41 | junit 42 | junit 43 | 44 | 45 | 46 | com.spring4all 47 | swagger-spring-boot-starter 48 | 1.9.0.RELEASE 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | src/main/java 59 | 60 | **/*.properties 61 | **/*.xml 62 | 63 | false 64 | 65 | 66 | src/main/resources 67 | 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-compiler-plugin 73 | 3.1 74 | 75 | true 76 | javac 77 | 1.8 78 | 1.8 79 | UTF-8 80 | 1.8 81 | true 82 | true 83 | 84 | 85 | 86 | org.codehaus.plexus 87 | plexus-compiler-eclipse 88 | 2.2 89 | 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-resources-plugin 95 | 3.0.1 96 | 97 | 98 | true 99 | 100 | 101 | 102 | org.apache.maven.plugins 103 | maven-war-plugin 104 | 2.1.1 105 | 106 | false 107 | upload/** 108 | 109 | 110 | 111 | org.springframework.boot 112 | spring-boot-maven-plugin 113 | 2.0.4.RELEASE 114 | 115 | 116 | 117 | repackage 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/GeneratorWebApplication.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator; 2 | 3 | import com.spring4all.swagger.EnableSwagger2Doc; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @EnableSwagger2Doc 9 | @SpringBootApplication 10 | public class GeneratorWebApplication { 11 | public static void main(String[] args) { 12 | SpringApplication.run(GeneratorWebApplication.class,args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.config; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.springframework.web.bind.annotation.ControllerAdvice; 6 | import org.springframework.web.bind.annotation.ExceptionHandler; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | 9 | import com.softdev.system.generator.util.ApiReturnObject; 10 | import com.softdev.system.generator.util.ApiReturnUtil; 11 | 12 | @ControllerAdvice 13 | public class GlobalDefaultExceptionHandler { 14 | 15 | @ExceptionHandler(Exception.class) 16 | @ResponseBody 17 | public ApiReturnObject defaultExceptionHandler(HttpServletRequest req,Exception e) { 18 | e.printStackTrace(); 19 | return ApiReturnUtil.error("服务器异常",e.getMessage()); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.web.context.WebServerInitializedEvent; 5 | import org.springframework.context.ApplicationListener; 6 | import org.springframework.stereotype.Component; 7 | import java.net.Inet4Address; 8 | import java.net.InetAddress; 9 | import java.net.UnknownHostException; 10 | 11 | /** 12 | * @Description 通过实现ApplicationListener接口动态获取tomcat启动端口,再通过InetAddress类获取主机的ip地址,最后控制台打印项目访问地址 13 | * @Author Gao Hang Hang 14 | * @Date 2019-12-27 14:37 15 | **/ 16 | @Component 17 | @Slf4j 18 | public class ServerConfig implements ApplicationListener { 19 | 20 | // tomcat启动端口 21 | private int serverPort; 22 | 23 | public int getPort() { 24 | return this.serverPort; 25 | } 26 | 27 | @Override 28 | public void onApplicationEvent(WebServerInitializedEvent event) { 29 | try { 30 | InetAddress inetAddress = Inet4Address.getLocalHost(); 31 | this.serverPort = event.getWebServer().getPort(); 32 | log.info("项目启动启动成功!访问地址: http://{}:{}", inetAddress.getHostAddress(), serverPort); 33 | } catch (UnknownHostException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.config; 2 | 3 | import com.alibaba.fastjson.support.config.FastJsonConfig; 4 | import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.http.converter.HttpMessageConverter; 8 | import org.springframework.http.converter.StringHttpMessageConverter; 9 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 11 | 12 | import java.nio.charset.Charset; 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | * 2019-2-11 liutf WebMvcConfig 整合 cors 和 SpringMvc MessageConverter 19 | */ 20 | @Configuration 21 | public class WebMvcConfig implements WebMvcConfigurer { 22 | 23 | /* @Override 24 | public void addCorsMappings(CorsRegistry registry) { 25 | registry.addMapping("/**") 26 | .allowedOrigins("*") 27 | .allowedHeaders("x-requested-with") 28 | .allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE") 29 | .maxAge(3600); 30 | }*/ 31 | 32 | @Override 33 | public void configureMessageConverters(List> converters) { 34 | //FastJsonHttpMessageConverter 35 | FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); 36 | 37 | List fastMediaTypes = new ArrayList<>(); 38 | fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); 39 | fastConverter.setSupportedMediaTypes(fastMediaTypes); 40 | 41 | FastJsonConfig fastJsonConfig = new FastJsonConfig(); 42 | fastJsonConfig.setCharset(StandardCharsets.UTF_8); 43 | fastConverter.setFastJsonConfig(fastJsonConfig); 44 | 45 | //StringHttpMessageConverter 46 | StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(); 47 | stringConverter.setDefaultCharset(StandardCharsets.UTF_8); 48 | stringConverter.setSupportedMediaTypes(fastMediaTypes); 49 | converters.add(stringConverter); 50 | converters.add(fastConverter); 51 | } 52 | 53 | @Override 54 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 55 | registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); 56 | registry.addResourceHandler("swagger-ui.html") 57 | .addResourceLocations("classpath:/META-INF/resources/"); 58 | 59 | registry.addResourceHandler("/webjars/**") 60 | .addResourceLocations("classpath:/META-INF/resources/webjars/"); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.controller; 2 | 3 | import com.softdev.system.generator.entity.ClassInfo; 4 | import com.softdev.system.generator.entity.ReturnT; 5 | import com.softdev.system.generator.util.CodeGeneratorTool; 6 | import com.softdev.system.generator.util.FreemarkerTool; 7 | import freemarker.template.TemplateException; 8 | import io.swagger.annotations.ApiOperation; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.web.bind.annotation.*; 14 | import java.io.IOException; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | /** 19 | * spring boot code generator 20 | * 21 | * @author zhengk/moshow 22 | */ 23 | @Controller 24 | @Slf4j 25 | public class IndexController { 26 | 27 | @Autowired 28 | private FreemarkerTool freemarkerTool; 29 | 30 | @GetMapping("/") 31 | public String index() { 32 | return "index"; 33 | } 34 | 35 | @PostMapping("/genCode") 36 | @ResponseBody 37 | public ReturnT> codeGenerate(String tableSql, 38 | //2019-2-10 liutf 修改为@RequestParam参数校验 39 | @RequestParam(required = false, defaultValue = "Gao Hang Hang") String authorName, 40 | @RequestParam(required = false, defaultValue = "com.gaohanghang.system") String packageName, 41 | @RequestParam(required = false, defaultValue = "ApiReturnUtil") String returnUtil 42 | ) { 43 | 44 | 45 | try { 46 | 47 | if (StringUtils.isBlank(tableSql)) { 48 | return new ReturnT<>(ReturnT.FAIL_CODE, "表结构信息不可为空"); 49 | } 50 | 51 | // parse table 52 | ClassInfo classInfo = CodeGeneratorTool.processTableIntoClassInfo(tableSql); 53 | 54 | // code genarete 55 | Map params = new HashMap(); 56 | params.put("classInfo", classInfo); 57 | params.put("authorName", authorName); 58 | params.put("packageName", packageName); 59 | params.put("returnUtil", returnUtil); 60 | 61 | // result 62 | Map result = new HashMap(); 63 | 64 | //UI 65 | result.put("swagger-ui", freemarkerTool.processString("code-generator/ui/swagger-ui.ftl", params)); 66 | result.put("element-ui", freemarkerTool.processString("code-generator/ui/element-ui.ftl", params)); 67 | result.put("bootstrap-ui", freemarkerTool.processString("code-generator/ui/bootstrap-ui.ftl", params)); 68 | //mybatis old 69 | result.put("controller", freemarkerTool.processString("code-generator/mybatis/controller.ftl", params)); 70 | result.put("service", freemarkerTool.processString("code-generator/mybatis/service.ftl", params)); 71 | result.put("service_impl", freemarkerTool.processString("code-generator/mybatis/service_impl.ftl", params)); 72 | result.put("mapper", freemarkerTool.processString("code-generator/mybatis/mapper.ftl", params)); 73 | result.put("mybatis", freemarkerTool.processString("code-generator/mybatis/mybatis.ftl", params)); 74 | result.put("model", freemarkerTool.processString("code-generator/mybatis/model.ftl", params)); 75 | //jpa 76 | result.put("entity", freemarkerTool.processString("code-generator/jpa/entity.ftl", params)); 77 | result.put("repository", freemarkerTool.processString("code-generator/jpa/repository.ftl", params)); 78 | result.put("jpacontroller", freemarkerTool.processString("code-generator/jpa/jpacontroller.ftl", params)); 79 | //jpa-new 80 | result.put("jpa-new-entity", freemarkerTool.processString("code-generator/jpa-new/entity.ftl", params)); 81 | result.put("jpa-new-repository", freemarkerTool.processString("code-generator/jpa-new/repository.ftl", params)); 82 | result.put("jpa-new-controller", freemarkerTool.processString("code-generator/jpa-new/jpacontroller.ftl", params)); 83 | result.put("jpa-new-service", freemarkerTool.processString("code-generator/jpa-new/service.ftl", params)); 84 | //Util 85 | result.put("util", freemarkerTool.processString("code-generator/util/util.ftl", params)); 86 | //jdbc template 87 | result.put("jtdao", freemarkerTool.processString("code-generator/jdbc-template/jtdao.ftl", params)); 88 | result.put("jtdaoimpl", freemarkerTool.processString("code-generator/jdbc-template/jtdaoimpl.ftl", params)); 89 | //beetsql 90 | result.put("beetlmd", freemarkerTool.processString("code-generator/beetlsql/beetlmd.ftl", params)); 91 | result.put("beetlentity", freemarkerTool.processString("code-generator/beetlsql/beetlentity.ftl", params)); 92 | result.put("beetlentitydto", freemarkerTool.processString("code-generator/beetlsql/beetlentitydto.ftl", params)); 93 | result.put("beetlcontroller", freemarkerTool.processString("code-generator/beetlsql/beetlcontroller.ftl", params)); 94 | //mybatis plus 95 | result.put("pluscontroller", freemarkerTool.processString("code-generator/mybatis-plus/pluscontroller.ftl", params)); 96 | result.put("plusmapper", freemarkerTool.processString("code-generator/mybatis-plus/plusmapper.ftl", params)); 97 | //sql generate 98 | result.put("select", freemarkerTool.processString("sql-generator/pgsql/select.ftl", params)); 99 | result.put("insert", freemarkerTool.processString("sql-generator/pgsql/insert.ftl", params)); 100 | result.put("update", freemarkerTool.processString("sql-generator/pgsql/update.ftl", params)); 101 | result.put("delete", freemarkerTool.processString("sql-generator/pgsql/delete.ftl", params)); 102 | //jpa-restful 103 | result.put("jpa-rest-entity", freemarkerTool.processString("code-generator/jpa-rest/entity.ftl", params)); 104 | result.put("jpa-rest-dto", freemarkerTool.processString("code-generator/jpa-rest/dto.ftl", params)); 105 | result.put("jpa-rest-vo", freemarkerTool.processString("code-generator/jpa-rest/vo.ftl", params)); 106 | result.put("jpa-rest-add-param", freemarkerTool.processString("code-generator/jpa-rest/addparam.ftl", params)); 107 | result.put("jpa-rest-update-param", freemarkerTool.processString("code-generator/jpa-rest/updateparam.ftl", params)); 108 | result.put("jpa-rest-page-param", freemarkerTool.processString("code-generator/jpa-rest/pageparam.ftl", params)); 109 | result.put("projection", freemarkerTool.processString("code-generator/jpa-rest/projection.ftl", params)); 110 | result.put("jpa-rest-repository", freemarkerTool.processString("code-generator/jpa-rest/repository.ftl", params)); 111 | result.put("jpa-rest-controller", freemarkerTool.processString("code-generator/jpa-rest/jpacontroller.ftl", params)); 112 | result.put("jpa-rest-service", freemarkerTool.processString("code-generator/jpa-rest/service.ftl", params)); 113 | result.put("jpa-rest-test", freemarkerTool.processString("code-generator/jpa-rest/test.ftl", params)); 114 | 115 | 116 | // 计算,生成代码行数 117 | int lineNum = 0; 118 | for (Map.Entry item : result.entrySet()) { 119 | if (item.getValue() != null) { 120 | lineNum += StringUtils.countMatches(item.getValue(), "\n"); 121 | } 122 | } 123 | log.info("生成代码行数:{}", lineNum); 124 | //测试环境可自行开启 125 | //log.info("生成代码数据:{}", result); 126 | return new ReturnT<>(result); 127 | } catch (IOException | TemplateException e) { 128 | log.error(e.getMessage(), e); 129 | return new ReturnT<>(ReturnT.FAIL_CODE, "表结构解析失败" + e.getMessage()); 130 | } 131 | } 132 | 133 | /** 134 | * 输入表名和字段名生成建表语句(暂只支持 postgresql ) 135 | * TODO 支持生成mysql建表语句 136 | * 137 | * @param tableName 表名 138 | * @param fields 字段名 139 | * @param comments 注释 140 | * @param types 数据类型 141 | * @param lengths 数据项长度 142 | * @return sql 语句 143 | */ 144 | @GetMapping("/sqlGenerate") 145 | @ResponseBody 146 | @ApiOperation("输入表名和字段名生成建表语句") 147 | public String sqlGenerate(@RequestParam String tableName, String fields, String comments, String types, String lengths, String explanations) { 148 | tableName = "t_" + tableName.toLowerCase(); 149 | 150 | StringBuilder stringBuilder = new StringBuilder(); 151 | stringBuilder.append("DROP TABLE IF EXISTS \"public\".\"").append(tableName).append("\";\n"); 152 | stringBuilder.append("CREATE TABLE \"public\".\"").append(tableName).append("\" (\n").append("\"id\" varchar(255) NOT NULL,\n"); 153 | 154 | String[] fieldsArr = null; 155 | String[] commentsArr = null; 156 | String[] lengthsArr = null; 157 | String[] typesArr = null; 158 | String[] explanationsArr = null; 159 | 160 | // 字段 161 | if (StringUtils.isNotBlank(fields)) { 162 | if (fields.contains(" ")) { 163 | fieldsArr = fields.split(" "); 164 | } else { 165 | fieldsArr = fields.split(","); 166 | } 167 | } 168 | 169 | // 类型 170 | if (StringUtils.isNotBlank(types)) { 171 | if (types.contains(" ")) { 172 | typesArr = types.split(" "); 173 | } else { 174 | typesArr = types.split(","); 175 | } 176 | } 177 | 178 | // 注释 179 | if (StringUtils.isNotBlank(comments)) { 180 | if (comments.contains(" ")) { 181 | commentsArr = comments.split(" "); 182 | } else { 183 | commentsArr = comments.split(","); 184 | } 185 | } 186 | 187 | // 长度 188 | if (StringUtils.isNotBlank(lengths)) { 189 | if (lengths.contains(" ")) { 190 | lengthsArr = lengths.split(" "); 191 | } else { 192 | lengthsArr = lengths.split(","); 193 | } 194 | } 195 | 196 | if (StringUtils.isNotBlank(explanations)) { 197 | explanationsArr = explanations.split(" "); 198 | } 199 | 200 | for (int i = 0; i < fieldsArr.length; i++) { 201 | if ("id".equals(fieldsArr[i].toLowerCase())) { 202 | continue; 203 | } 204 | 205 | if (typesArr != null) { 206 | if (lengthsArr != null) { 207 | if (StringUtils.isNotBlank(typesArr[i]) && StringUtils.isNotBlank(lengthsArr[i])) { 208 | String type = conversionType(typesArr[i]); 209 | if (fieldsArr[i].toLowerCase().endsWith("_time")) { 210 | stringBuilder.append("\"").append(fieldsArr[i].toLowerCase()).append("\"").append(" timestamp(6),\n"); 211 | } else { 212 | if ("int4".equals(type)) { 213 | stringBuilder.append("\"").append(fieldsArr[i].toLowerCase()).append("\"").append(" " + type + ",\n"); 214 | } else { 215 | stringBuilder.append("\"").append(fieldsArr[i].toLowerCase()).append("\"").append(" " + type + "(" + lengthsArr[i] + "),\n"); 216 | } 217 | } 218 | } 219 | } else { 220 | if (fieldsArr[i].toLowerCase().endsWith("_time")) { 221 | stringBuilder.append("\"").append(fieldsArr[i].toLowerCase()).append("\"").append(" timestamp(6),\n"); 222 | } else { 223 | stringBuilder.append("\"").append(fieldsArr[i].toLowerCase()).append("\"").append(" varchar(").append(lengthsArr[i]).append("),\n"); 224 | } 225 | } 226 | } else { 227 | if (fieldsArr[i].toLowerCase().endsWith("_time")) { 228 | stringBuilder.append("\"").append(fieldsArr[i].toLowerCase()).append("\"").append(" timestamp(6),\n"); 229 | } else { 230 | stringBuilder.append("\"").append(fieldsArr[i].toLowerCase()).append("\"").append(" varchar(255),\n"); 231 | } 232 | } 233 | } 234 | 235 | stringBuilder.append("CONSTRAINT ").append("\"").append(tableName).append("_pkey").append("\"").append(" PRIMARY KEY (\"id\")\n" + 236 | ");\n"); 237 | 238 | stringBuilder.append("ALTER TABLE \"public\".\"").append(tableName).append("\"\n").append("OWNER TO \"postgres\";\n"); 239 | 240 | for (int i = 0; i < fieldsArr.length; i++) { 241 | if (commentsArr != null && commentsArr[i] != null) { 242 | if (explanationsArr != null && explanationsArr[i] != null) { 243 | stringBuilder.append("COMMENT ON COLUMN \"public\".\"").append(tableName).append("\".\"").append(fieldsArr[i].toLowerCase()).append("\" IS '").append(commentsArr[i]).append(" ").append(explanationsArr[i]).append("';\n"); 244 | } else { 245 | stringBuilder.append("COMMENT ON COLUMN \"public\".\"").append(tableName).append("\".\"").append(fieldsArr[i].toLowerCase()).append("\" IS '").append(commentsArr[i]).append("';\n"); 246 | } 247 | } 248 | } 249 | 250 | return stringBuilder.toString(); 251 | } 252 | 253 | /** 254 | * 转换数据类型 255 | * 256 | * @param typeAbbreviation 257 | * @return 258 | */ 259 | public String conversionType(String typeAbbreviation) { 260 | if ("C".equals(typeAbbreviation)) { 261 | return "varchar"; 262 | } else if ("N".equals(typeAbbreviation)) { 263 | return "int4"; 264 | } 265 | return null; 266 | } 267 | 268 | } 269 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/entity/ClassInfo.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * class info 9 | * 10 | * @author xuxueli 2018-05-02 20:02:34 11 | */ 12 | @Data 13 | public class ClassInfo { 14 | 15 | private String tableName; 16 | private String className; 17 | private String classComment; 18 | private List fieldList; 19 | 20 | } -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/entity/FieldInfo.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * field info 7 | * 8 | * @author xuxueli 2018-05-02 20:11:05 9 | */ 10 | @Data 11 | public class FieldInfo { 12 | 13 | private String columnName; 14 | private String fieldName; 15 | private String fieldClass; 16 | private String fieldComment; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/entity/ReturnT.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * common return 9 | * @author xuxueli 2015-12-4 16:32:31 10 | */ 11 | @Data 12 | public class ReturnT implements Serializable { 13 | 14 | public static final long serialVersionUID = 42L; 15 | 16 | public static final int SUCCESS_CODE = 200; 17 | public static final int FAIL_CODE = 500; 18 | public static final ReturnT SUCCESS = new ReturnT<>(null); 19 | public static final ReturnT FAIL = new ReturnT<>(FAIL_CODE, null); 20 | 21 | private int code; 22 | private String msg; 23 | private T data; 24 | 25 | public ReturnT(int code, String msg) { 26 | this.code = code; 27 | this.msg = msg; 28 | } 29 | public ReturnT(T data) { 30 | this.code = SUCCESS_CODE; 31 | this.data = data; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/ApiReturnObject.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | @Data 7 | public class ApiReturnObject implements Serializable{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | public ApiReturnObject(String errorCode, Object errorMessage, Object returnObject) { 12 | super(); 13 | this.errorCode = errorCode; 14 | this.errorMessage = errorMessage; 15 | this.returnObject = returnObject; 16 | } 17 | public ApiReturnObject(Object errorMessage, Object returnObject) { 18 | super(); 19 | this.errorMessage = errorMessage; 20 | this.returnObject = returnObject; 21 | } 22 | 23 | String errorCode="00"; 24 | Object errorMessage; 25 | Object returnObject; 26 | String pageNumber; 27 | String pageSize; 28 | String totalElements; 29 | String totalPages; 30 | 31 | public ApiReturnObject(String pageNumber,String pageSize,String totalElements,String totalPages,String errorCode, Object errorMessage, Object returnObject) { 32 | super(); 33 | this.pageNumber = pageNumber; 34 | this.errorCode = errorCode; 35 | this.errorMessage = errorMessage; 36 | this.returnObject = returnObject; 37 | this.pageSize = pageSize; 38 | this.totalElements = totalElements; 39 | this.totalPages = totalPages; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/ApiReturnUtil.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class ApiReturnUtil implements Serializable{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | public static ApiReturnObject error(Object errorMessage) { 12 | System.out.println(errorMessage); 13 | List object=new ArrayList(); 14 | return new ApiReturnObject("01",errorMessage,object); 15 | } 16 | public static ApiReturnObject error(Object errorMessage, Object returnObject) { 17 | List object=new ArrayList(); 18 | object.add(returnObject); 19 | return new ApiReturnObject("01",errorMessage,object); 20 | } 21 | public static ApiReturnObject success(Object returnObject) { 22 | if(returnObject instanceof java.util.List){ 23 | return new ApiReturnObject("00","success",returnObject); 24 | }else { 25 | List object=new ArrayList(); 26 | object.add(returnObject); 27 | return new ApiReturnObject("00","success",object); 28 | } 29 | } 30 | public static ApiReturnObject success(Object errorMessage, Object returnObject) { 31 | if(returnObject instanceof java.util.List){ 32 | return new ApiReturnObject("00",errorMessage,returnObject); 33 | }else { 34 | List object=new ArrayList(); 35 | object.add(returnObject); 36 | return new ApiReturnObject("00",errorMessage,object); 37 | } 38 | } 39 | public static ApiReturnObject pageManual(Integer pageNumber, Integer pageSize,Integer countNum, List returnObject) { 40 | return new ApiReturnObject(pageNumber+"",pageSize+"",countNum+"",getTotalPages(countNum, pageSize),"00","success",returnObject); 41 | } 42 | 43 | public static String getTotalPages(Integer countNum, Integer pageSize) { 44 | if((countNum%pageSize)==0) { 45 | return ((countNum/pageSize))+""; 46 | }else { 47 | return ((countNum/pageSize)+1)+""; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/BasePath.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | 4 | import javax.servlet.ServletContext; 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | public class BasePath { 8 | protected static String contextPath = null; 9 | protected static String basePath = null; 10 | protected static String realPath = null; 11 | 12 | public static String getBasePath(HttpServletRequest request) { 13 | contextPath = request.getContextPath(); 14 | basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+contextPath+"/"; 15 | return basePath; 16 | } 17 | 18 | public static String getRealPath(HttpServletRequest request, String path) { 19 | ServletContext context = request.getSession().getServletContext(); 20 | realPath = context.getRealPath(path); 21 | realPath = context.getRealPath(path)+"\\"; 22 | return realPath; 23 | } 24 | 25 | public static String getMyRealPath(HttpServletRequest request, String path) { 26 | ServletContext context = request.getSession().getServletContext(); 27 | realPath = context.getRealPath(path); 28 | realPath = context.getRealPath(path); 29 | return realPath; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/CodeGenerateException.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | /** 4 | * @author xuxueli 2018-05-02 21:10:28 5 | */ 6 | public class CodeGenerateException extends RuntimeException { 7 | private static final long serialVersionUID = 42L; 8 | public CodeGenerateException() { 9 | super(); 10 | } 11 | 12 | public CodeGenerateException(String msg) { 13 | super(msg); 14 | } 15 | 16 | public CodeGenerateException(String msg, Throwable cause) { 17 | super(msg, cause); 18 | } 19 | 20 | public CodeGenerateException(Throwable cause) { 21 | super(cause); 22 | } 23 | 24 | public CodeGenerateException(String message, Throwable cause, 25 | boolean enableSuppression, 26 | boolean writableStackTrace) { 27 | super(message, cause, enableSuppression, writableStackTrace); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/CodeGeneratorTool.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | 4 | 5 | import com.softdev.system.generator.entity.ClassInfo; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * code generate tool 11 | * 12 | * @author xuxueli 2018-04-25 16:29:58 13 | */ 14 | public class CodeGeneratorTool { 15 | 16 | /** 17 | * process Table Into ClassInfo 18 | * 19 | * @param tableSql 20 | * @return 21 | */ 22 | public static ClassInfo processTableIntoClassInfo(String tableSql) throws IOException { 23 | return TableParseUtil.processTableIntoClassInfo(tableSql); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerTool.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | import freemarker.template.Configuration; 4 | import freemarker.template.Template; 5 | import freemarker.template.TemplateException; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.io.IOException; 10 | import java.io.StringWriter; 11 | import java.util.Map; 12 | 13 | /** 14 | * freemarker tool 15 | * 16 | * @author xuxueli 2018-05-02 19:56:00 17 | */ 18 | @Component 19 | public class FreemarkerTool { 20 | 21 | @Autowired 22 | private Configuration configuration; 23 | 24 | /** 25 | * process Template Into String 26 | * 27 | * @param template 28 | * @param model 29 | * @return 30 | * @throws IOException 31 | * @throws TemplateException 32 | */ 33 | public String processTemplateIntoString(Template template, Object model) 34 | throws IOException, TemplateException { 35 | 36 | StringWriter result = new StringWriter(); 37 | template.process(model, result); 38 | return result.toString(); 39 | } 40 | 41 | /** 42 | * process String 43 | * 44 | * @param templateName 45 | * @param params 46 | * @return 47 | * @throws IOException 48 | * @throws TemplateException 49 | */ 50 | public String processString(String templateName, Map params) 51 | throws IOException, TemplateException { 52 | 53 | Template template = configuration.getTemplate(templateName); 54 | String htmlText = processTemplateIntoString(template, params); 55 | return htmlText; 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | import freemarker.template.Configuration; 4 | import freemarker.template.Template; 5 | import freemarker.template.TemplateException; 6 | import freemarker.template.TemplateExceptionHandler; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.io.StringWriter; 13 | import java.util.Locale; 14 | import java.util.Map; 15 | 16 | /** 17 | * freemarker tool 18 | * 19 | * @author xuxueli 2018-05-02 19:56:00 20 | */ 21 | public class FreemarkerUtil { 22 | private static final Logger logger = LoggerFactory.getLogger(CodeGeneratorTool.class); 23 | 24 | /** 25 | * freemarker config 26 | */ 27 | private static Configuration freemarkerConfig = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); 28 | static{ 29 | String templatePath = Thread.currentThread().getContextClassLoader().getResource("").getPath(); 30 | int wei = templatePath.lastIndexOf("WEB-INF/classes/"); 31 | if (wei > -1) { 32 | templatePath = templatePath.substring(0, wei); 33 | } 34 | 35 | try { 36 | freemarkerConfig.setDirectoryForTemplateLoading(new File(templatePath, "templates/xxl-code-generator")); 37 | freemarkerConfig.setNumberFormat("#"); 38 | freemarkerConfig.setClassicCompatible(true); 39 | freemarkerConfig.setDefaultEncoding("UTF-8"); 40 | freemarkerConfig.setLocale(Locale.CHINA); 41 | freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); 42 | } catch (IOException e) { 43 | logger.error(e.getMessage(), e); 44 | } 45 | } 46 | 47 | /** 48 | * process Template Into String 49 | * 50 | * @param template 51 | * @param model 52 | * @return 53 | * @throws IOException 54 | * @throws TemplateException 55 | */ 56 | public static String processTemplateIntoString(Template template, Object model) 57 | throws IOException, TemplateException { 58 | 59 | StringWriter result = new StringWriter(); 60 | template.process(model, result); 61 | return result.toString(); 62 | } 63 | 64 | /** 65 | * process String 66 | * 67 | * @param templateName 68 | * @param params 69 | * @return 70 | * @throws IOException 71 | * @throws TemplateException 72 | */ 73 | public static String processString(String templateName, Map params) 74 | throws IOException, TemplateException { 75 | 76 | Template template = freemarkerConfig.getTemplate(templateName); 77 | String htmlText = processTemplateIntoString(template, params); 78 | return htmlText; 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/StringPlusUtils.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | /** 4 | * string tool 5 | * 6 | * @author xuxueli 2018-05-02 20:43:25 7 | */ 8 | public class StringPlusUtils { 9 | 10 | /** 11 | * 首字母大写 12 | * 13 | * @param str 14 | * @return 15 | */ 16 | public static String upperCaseFirst(String str) { 17 | return str.substring(0, 1).toUpperCase() + str.substring(1); 18 | } 19 | 20 | /** 21 | * 首字母小写 22 | * 23 | * @param str 24 | * @return 25 | */ 26 | public static String lowerCaseFirst(String str) { 27 | return str.substring(0, 1).toLowerCase() + str.substring(1); 28 | } 29 | 30 | /** 31 | * 下划线,转换为驼峰式 32 | * 33 | * @param underscoreName 34 | * @return 35 | */ 36 | public static String underlineToCamelCase(String underscoreName) { 37 | StringBuilder result = new StringBuilder(); 38 | if (underscoreName != null && underscoreName.trim().length() > 0) { 39 | boolean flag = false; 40 | for (int i = 0; i < underscoreName.length(); i++) { 41 | char ch = underscoreName.charAt(i); 42 | if ("_".charAt(0) == ch) { 43 | flag = true; 44 | } else { 45 | if (flag) { 46 | result.append(Character.toUpperCase(ch)); 47 | flag = false; 48 | } else { 49 | result.append(ch); 50 | } 51 | } 52 | } 53 | } 54 | return result.toString(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | /** 4 | * string tool 5 | * 6 | * @author xuxueli 2018-05-02 20:43:25 7 | */ 8 | public class StringUtils { 9 | 10 | /** 11 | * 首字母大写 12 | * 13 | * @param str 14 | * @return 15 | */ 16 | public static String upperCaseFirst(String str) { 17 | return str.substring(0, 1).toUpperCase() + str.substring(1); 18 | } 19 | 20 | /** 21 | * 首字母小写 22 | * 23 | * @param str 24 | * @return 25 | */ 26 | public static String lowerCaseFirst(String str) { 27 | //2019-2-10 解决StringUtils.lowerCaseFirst潜在的NPE异常@liutf 28 | return (str!=null&&str.length()>1)?str.substring(0, 1).toLowerCase() + str.substring(1):""; 29 | } 30 | 31 | /** 32 | * 下划线,转换为驼峰式 33 | * 34 | * @param underscoreName 35 | * @return 36 | */ 37 | public static String underlineToCamelCase(String underscoreName) { 38 | StringBuilder result = new StringBuilder(); 39 | if (underscoreName != null && underscoreName.trim().length() > 0) { 40 | boolean flag = false; 41 | for (int i = 0; i < underscoreName.length(); i++) { 42 | char ch = underscoreName.charAt(i); 43 | if ("_".charAt(0) == ch) { 44 | flag = true; 45 | } else { 46 | if (flag) { 47 | result.append(Character.toUpperCase(ch)); 48 | flag = false; 49 | } else { 50 | result.append(ch); 51 | } 52 | } 53 | } 54 | } 55 | return result.toString(); 56 | } 57 | 58 | public static void main(String[] args) { 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java: -------------------------------------------------------------------------------- 1 | package com.softdev.system.generator.util; 2 | 3 | 4 | import com.softdev.system.generator.entity.ClassInfo; 5 | import com.softdev.system.generator.entity.FieldInfo; 6 | 7 | import java.io.IOException; 8 | import java.math.BigDecimal; 9 | import java.time.LocalDate; 10 | import java.time.LocalDateTime; 11 | import java.util.ArrayList; 12 | import java.util.Date; 13 | import java.util.List; 14 | import java.util.regex.Matcher; 15 | import java.util.regex.Pattern; 16 | 17 | /** 18 | * @author xuxueli 2018-05-02 21:10:45 19 | * @modify zhengk/moshow 20180913 20 | */ 21 | public class TableParseUtil { 22 | 23 | /** 24 | * 解析建表SQL生成代码(model-dao-xml) 25 | * 26 | * @param tableSql 27 | * @return 28 | */ 29 | public static ClassInfo processTableIntoClassInfo(String tableSql) throws IOException { 30 | if (tableSql==null || tableSql.trim().length()==0) { 31 | throw new CodeGenerateException("Table structure can not be empty."); 32 | } 33 | tableSql = tableSql.trim().replaceAll("'","`").replaceAll("\"","`").replaceAll(",",",").toLowerCase(); 34 | 35 | // table Name 36 | String tableName = null; 37 | if (tableSql.contains("TABLE") && tableSql.contains("(")) { 38 | tableName = tableSql.substring(tableSql.indexOf("TABLE")+5, tableSql.indexOf("(")); 39 | } else if (tableSql.contains("table") && tableSql.contains("(")) { 40 | tableName = tableSql.substring(tableSql.indexOf("table")+5, tableSql.indexOf("(")); 41 | } else { 42 | throw new CodeGenerateException("Table structure anomaly."); 43 | } 44 | 45 | //新增处理create table if not exists members情况 46 | if (tableName.contains("if not exists")) tableName=tableName.replaceAll("if not exists",""); 47 | 48 | if (tableName.contains("`")) { 49 | tableName = tableName.substring(tableName.indexOf("`")+1, tableName.lastIndexOf("`")); 50 | }else{ 51 | //空格开头的,需要替换掉\n\t空格 52 | tableName=tableName.replaceAll(" ","").replaceAll("\n","").replaceAll("\t",""); 53 | } 54 | //优化对byeas`.`ct_bd_customerdiscount这种命名的支持 55 | if(tableName.contains("`.`")){ 56 | tableName=tableName.substring(tableName.indexOf("`.`")+3); 57 | }else if(tableName.contains(".")){ 58 | //优化对likeu.members这种命名的支持 59 | tableName=tableName.substring(tableName.indexOf(".")+1); 60 | } 61 | // class Name 62 | String className = StringUtils.upperCaseFirst(StringUtils.underlineToCamelCase(tableName)); 63 | if (className.contains("_")) { 64 | className = className.replaceAll("_", ""); 65 | } 66 | 67 | // class Comment 68 | String classComment = null; 69 | //mysql是comment=,pgsql/oracle是comment on table, 70 | if (tableSql.contains("comment=")) { 71 | String classCommentTmp = tableSql.substring(tableSql.lastIndexOf("comment=")+8).replaceAll("`","").trim(); 72 | if (classCommentTmp.indexOf(" ")!=classCommentTmp.lastIndexOf(" ")) { 73 | classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf(" ")+1, classCommentTmp.lastIndexOf(" ")); 74 | } 75 | if (classCommentTmp!=null && classCommentTmp.trim().length()>0) { 76 | classComment = classCommentTmp; 77 | }else{ 78 | //修复表备注为空问题 79 | classComment = className; 80 | } 81 | }else if(tableSql.contains("comment on table")) { 82 | //COMMENT ON TABLE CT_BAS_FEETYPE IS 'CT_BAS_FEETYPE'; 83 | String classCommentTmp = tableSql.substring(tableSql.lastIndexOf("comment on table")+17).trim(); 84 | //证明这是一个常规的COMMENT ON TABLE xxx IS 'xxxx' 85 | if (classCommentTmp.contains("`")) { 86 | classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf("`")+1); 87 | classCommentTmp = classCommentTmp.substring(0,classCommentTmp.indexOf("`")); 88 | classComment = classCommentTmp; 89 | }else{ 90 | //非常规的没法分析 91 | classComment = tableName; 92 | } 93 | }else{ 94 | //修复表备注为空问题 95 | classComment = tableName; 96 | } 97 | //如果备注跟;混在一起,需要替换掉 98 | classComment=classComment.replaceAll(";",""); 99 | // field List 100 | List fieldList = new ArrayList(); 101 | 102 | // 正常( ) 内的一定是字段相关的定义。 103 | String fieldListTmp = tableSql.substring(tableSql.indexOf("(")+1, tableSql.lastIndexOf(")")); 104 | 105 | // 匹配 comment,替换备注里的小逗号, 防止不小心被当成切割符号切割 106 | Matcher matcher = Pattern.compile("comment `(.*?)\\`").matcher(fieldListTmp); // "\\{(.*?)\\}" 107 | while(matcher.find()){ 108 | 109 | String commentTmp = matcher.group(); 110 | //2018-9-27 zhengk 不替换,只处理,支持COMMENT评论里面多种注释 111 | //commentTmp = commentTmp.replaceAll("\\ comment `|\\`", " "); // "\\{|\\}" 112 | 113 | if (commentTmp.contains(",")) { 114 | String commentTmpFinal = commentTmp.replaceAll(",", ","); 115 | fieldListTmp = fieldListTmp.replace(matcher.group(), commentTmpFinal); 116 | } 117 | } 118 | //2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况 119 | Matcher matcher2 = Pattern.compile("\\`(.*?)\\`").matcher(fieldListTmp); // "\\{(.*?)\\}" 120 | while(matcher2.find()){ 121 | String commentTmp2 = matcher2.group(); 122 | if (commentTmp2.contains(",")) { 123 | String commentTmpFinal = commentTmp2.replaceAll(",", ",").replaceAll("\\(", "(").replaceAll("\\)", ")"); 124 | fieldListTmp = fieldListTmp.replace(matcher2.group(), commentTmpFinal); 125 | } 126 | } 127 | //2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况 128 | Matcher matcher3 = Pattern.compile("\\((.*?)\\)").matcher(fieldListTmp); // "\\{(.*?)\\}" 129 | while(matcher3.find()){ 130 | String commentTmp3 = matcher3.group(); 131 | if (commentTmp3.contains(",")) { 132 | String commentTmpFinal = commentTmp3.replaceAll(",", ","); 133 | fieldListTmp = fieldListTmp.replace(matcher3.group(), commentTmpFinal); 134 | } 135 | } 136 | String[] fieldLineList = fieldListTmp.split(","); 137 | if (fieldLineList.length > 0) { 138 | int i=0; 139 | //i为了解决primary key关键字出现的地方,出现在前3行,一般和id有关 140 | for (String columnLine :fieldLineList) { 141 | i++; 142 | columnLine = columnLine.replaceAll("\n","").replaceAll("\t","").trim(); 143 | // `userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID', 144 | // 2018-9-18 zhengk 修改为contains,提升匹配率和匹配不按照规矩出牌的语句 145 | // 2018-11-8 zhengkai 修复tornadoorz反馈的KEY FK_permission_id (permission_id),KEY FK_role_id (role_id)情况 146 | // 2019-2-22 zhengkai 要在条件中使用复杂的表达式 147 | // 2019-4-29 zhengkai 优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 ) 148 | boolean specialFlag=(!columnLine.contains("key ")&&!columnLine.contains("constraint")&&!columnLine.contains("using")&&!columnLine.contains("unique") 149 | &&!(columnLine.contains("primary")&&columnLine.indexOf("storage")+3>columnLine.indexOf("(")) 150 | &&!columnLine.contains("pctincrease") 151 | &&!columnLine.contains("buffer_pool")&&!columnLine.contains("tablespace") 152 | &&!(columnLine.contains("primary")&&i>3)); 153 | 154 | if (specialFlag){ 155 | //如果是oracle的number(x,x),可能出现最后分割残留的,x),这里做排除处理 156 | if(columnLine.length()<5) {continue;} 157 | //2018-9-16 zhengkai 支持'符号以及空格的oracle语句// userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID', 158 | String columnName = ""; 159 | columnLine=columnLine.replaceAll("`"," ").replaceAll("\""," ").replaceAll("'","").replaceAll(" "," ").trim(); 160 | //如果遇到username varchar(65) default '' not null,这种情况,判断第一个空格是否比第一个引号前 161 | columnName = columnLine.substring(0, columnLine.indexOf(" ")); 162 | 163 | // field Name 164 | String fieldName = StringUtils.lowerCaseFirst(StringUtils.underlineToCamelCase(columnName)); 165 | if (fieldName.contains("_")) { 166 | fieldName = fieldName.replaceAll("_", ""); 167 | } 168 | 169 | // field class 170 | columnLine = columnLine.substring(columnLine.indexOf("`")+1).trim(); 171 | // int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID', 172 | String fieldClass = Object.class.getSimpleName(); 173 | //2018-9-16 zhengk 补充char/clob/blob/json等类型,如果类型未知,默认为String 174 | //2018-11-22 lshz0088 处理字段类型的时候,不严谨columnLine.contains(" int") 类似这种的,可在前后适当加一些空格之类的加以区分,否则当我的字段包含这些字符的时候,产生类型判断问题。 175 | if (columnLine.contains(" int") || columnLine.contains("tinyint") || columnLine.contains("smallint")) { 176 | fieldClass = Integer.class.getSimpleName(); 177 | } else if (columnLine.contains("bool")) { 178 | fieldClass = Boolean.class.getSimpleName(); 179 | } else if (columnLine.contains("bigint")) { 180 | fieldClass = Long.class.getSimpleName(); 181 | } else if (columnLine.contains("float")) { 182 | fieldClass = Float.class.getSimpleName(); 183 | } else if (columnLine.contains("double")) { 184 | fieldClass = Double.class.getSimpleName(); 185 | } else if (columnLine.contains("datetime") || columnLine.contains("timestamp")) { 186 | fieldClass = LocalDateTime.class.getSimpleName(); 187 | } else if (columnLine.contains("date")) { 188 | fieldClass = LocalDate.class.getSimpleName(); 189 | } else if (columnLine.contains("varchar") || columnLine.contains(" text")|| columnLine.contains("char") 190 | || columnLine.contains("clob")||columnLine.contains("blob")||columnLine.contains("json")) { 191 | fieldClass = String.class.getSimpleName(); 192 | } else if (columnLine.contains("decimal")||columnLine.contains(" number")) { 193 | //2018-11-22 lshz0088 建议对number类型增加int,long,BigDecimal的区分判断 194 | //如果startKh大于等于0,则表示有设置取值范围 195 | int startKh=columnLine.indexOf("("); 196 | if(startKh>=0){ 197 | int endKh=columnLine.indexOf(")",startKh); 198 | String[] fanwei=columnLine.substring(startKh+1,endKh).split(","); 199 | //2019-1-5 zhengk 修复@arthaschan反馈的超出范围错误 200 | //System.out.println("fanwei"+ JSON.toJSONString(fanwei)); 201 | // //number(20,6) fanwei["20","6"] 202 | // //number(0,6) fanwei["0","6"] 203 | // //number(20,0) fanwei["20","0"] 204 | // //number(20) fanwei["20"] 205 | //如果括号里是1位或者2位且第二位为0,则进行特殊处理。只有有小数位,都设置为BigDecimal。 206 | if((fanwei.length>1&&"0".equals(fanwei[1]))||fanwei.length==1){ 207 | int length=Integer.parseInt(fanwei[0]); 208 | if(fanwei.length>1) { 209 | length=Integer.valueOf(fanwei[1]); 210 | } 211 | //数字范围9位及一下用Integer,大的用Long 212 | if(length<=9){ 213 | fieldClass = Integer.class.getSimpleName(); 214 | }else{ 215 | fieldClass = Long.class.getSimpleName(); 216 | } 217 | }else{ 218 | //有小数位数一律使用BigDecimal 219 | fieldClass = BigDecimal.class.getSimpleName(); 220 | } 221 | }else{ 222 | fieldClass = BigDecimal.class.getSimpleName(); 223 | } 224 | }else { 225 | fieldClass = String.class.getSimpleName(); 226 | } 227 | 228 | // field comment,MySQL的一般位于field行,而pgsql和oralce多位于后面。 229 | String fieldComment = null; 230 | if(tableSql.contains("comment on column")&&(tableSql.contains("."+columnName+" is ")||tableSql.contains(".`"+columnName+"` is"))){ 231 | //新增对pgsql/oracle的字段备注支持 232 | //COMMENT ON COLUMN public.check_info.check_name IS '检查者名称'; 233 | //2018-11-22 lshz0088 正则表达式的点号前面应该加上两个反斜杠,否则会认为是任意字符 234 | //2019-4-29 zhengkai 优化对oracle注释comment on column的支持(@liukex) 235 | tableSql=tableSql.replaceAll(".`"+columnName+"` is","."+columnName+" is"); 236 | Matcher columnCommentMatcher = Pattern.compile("\\."+columnName+" is `").matcher(tableSql); 237 | fieldComment=columnName; 238 | while(columnCommentMatcher.find()){ 239 | String columnCommentTmp = columnCommentMatcher.group(); 240 | System.out.println(columnCommentTmp); 241 | fieldComment = tableSql.substring(tableSql.indexOf(columnCommentTmp)+columnCommentTmp.length()).trim(); 242 | fieldComment = fieldComment.substring(0,fieldComment.indexOf("`")).trim(); 243 | } 244 | }else if (columnLine.contains("comment")) { 245 | String commentTmp = columnLine.substring(columnLine.indexOf("comment")+7).trim(); 246 | // '用户ID', 247 | if (commentTmp.contains("`") || commentTmp.indexOf("`")!=commentTmp.lastIndexOf("`")) { 248 | commentTmp = commentTmp.substring(commentTmp.indexOf("`")+1, commentTmp.lastIndexOf("`")); 249 | } 250 | //解决最后一句是评论,无主键且连着)的问题:album_id int(3) default '1' null comment '相册id:0 代表头像 1代表照片墙') 251 | if(commentTmp.contains(")")){ 252 | commentTmp = commentTmp.substring(0, commentTmp.lastIndexOf(")")+1); 253 | } 254 | fieldComment = commentTmp; 255 | }else{ 256 | //修复comment不存在导致报错的问题 257 | fieldComment = columnName; 258 | } 259 | 260 | FieldInfo fieldInfo = new FieldInfo(); 261 | fieldInfo.setColumnName(columnName); 262 | fieldInfo.setFieldName(fieldName); 263 | fieldInfo.setFieldClass(fieldClass); 264 | fieldInfo.setFieldComment(fieldComment); 265 | 266 | fieldList.add(fieldInfo); 267 | } 268 | } 269 | } 270 | 271 | if (fieldList.size() < 1) { 272 | throw new CodeGenerateException("表结构分析失败,请检查语句或者提交issue给我"); 273 | } 274 | 275 | ClassInfo codeJavaInfo = new ClassInfo(); 276 | codeJavaInfo.setTableName(tableName); 277 | codeJavaInfo.setClassName(className); 278 | codeJavaInfo.setClassComment(classComment); 279 | codeJavaInfo.setFieldList(fieldList); 280 | 281 | return codeJavaInfo; 282 | } 283 | 284 | } 285 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 1234 3 | # servlet: 4 | # context-path: /generator 5 | 6 | tomcat: 7 | remote-ip-header: x-forward-for 8 | uri-encoding: UTF-8 9 | max-threads: 10 10 | background-processor-delay: 30 11 | basedir: ${user.home}/tomcat/ 12 | spring: 13 | cloud: 14 | nacos: 15 | discovery: 16 | server-addr: 127.0.0.1:8848 17 | banner: 18 | charset: UTF-8 19 | http: 20 | encoding: 21 | force: true 22 | charset: UTF-8 23 | application: 24 | name: spring-boot-code-generator 25 | freemarker: 26 | request-context-attribute: request 27 | suffix: .ftl 28 | content-type: text/html 29 | enabled: true 30 | cache: false 31 | charset: UTF-8 32 | allow-request-override: false 33 | expose-request-attributes: true 34 | expose-session-attributes: true 35 | expose-spring-macro-helpers: true 36 | #template-loader-path: classpath:/templates/ 37 | mvc: 38 | static-path-pattern: /static/** 39 | 40 | # swagger配置 41 | swagger: 42 | # 是否启用swagger,默认:true 43 | enabled: true 44 | # 标题 45 | title: "Spring Boot 测试使用 Swagger2 构建RESTful API" 46 | contact: 47 | # 维护人 48 | name: "yunlingfly" 49 | email: "508821881@qq.com" 50 | url: "https://www.yunlingfly.cn" 51 | # 版本 52 | version: "1.0" 53 | # 描述 54 | description: "API 描述" 55 | # swagger扫描的基础包,默认:全扫描 56 | base-package: "com.softdev.system.generator.controller" 57 | # 需要处理的基础URL规则,默认:/** 58 | base-path: /** 59 | # 需要排除的URL规则,默认:空 60 | # exclude-path: "" 61 | license: "Apache License, Version 2.0" 62 | license-url: "https://www.apache.org/licenses/LICENSE-2.0.html" 63 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hacker-and-painter/spring-boot-code-generator/cad403fc56934b250da9be6afee59d3e70d06dcb/generator-web/src/main/resources/favicon.ico -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl: -------------------------------------------------------------------------------- 1 | import org.springframework.web.bind.annotation.RequestMapping; 2 | import org.springframework.web.bind.annotation.RequestParam; 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * ${classInfo.classComment} 11 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 12 | */ 13 | @RestController 14 | @RequestMapping("/${classInfo.className?uncap_first}") 15 | public class ${classInfo.className}Controller { 16 | 17 | @Autowired 18 | private SQLManager sqlManager; 19 | 20 | /** 21 | * 新增或编辑 22 | */ 23 | @PostMapping("/save") 24 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 25 | ${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,${classInfo.className?uncap_first}.getId()); 26 | if(${classInfo.className?uncap_first}!=null){ 27 | sqlManager.updateById(${classInfo.className?uncap_first}); 28 | return ${returnUtil}.success("编辑成功"); 29 | }else{ 30 | sqlManager.insert(${classInfo.className?uncap_first}); 31 | return ${returnUtil}.error("保存成功"); 32 | } 33 | } 34 | 35 | /** 36 | * 删除 37 | */ 38 | @PostMapping("/delete") 39 | public Object delete(int id){ 40 | ${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,id); 41 | if(${classInfo.className?uncap_first}!=null){ 42 | sqlManager.deleteById(id); 43 | return ${returnUtil}.success("删除成功"); 44 | }else{ 45 | return ${returnUtil}.error("没有找到该对象"); 46 | } 47 | } 48 | 49 | /** 50 | * 查询 51 | */ 52 | @PostMapping("/find") 53 | public Object find(int id){ 54 | ${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,id); 55 | if(${classInfo.className?uncap_first}!=null){ 56 | return ${returnUtil}.success(${classInfo.className?uncap_first}); 57 | }else{ 58 | return ${returnUtil}.error("没有找到该对象"); 59 | } 60 | } 61 | 62 | /** 63 | * 分页查询 64 | */ 65 | @PostMapping("/list") 66 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 67 | @RequestParam(required = false, defaultValue = "0") int pageNumber, 68 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 69 | List<${classInfo.className}> list = sqlManager.query(${classInfo.className}.class).select(); 70 | return ${returnUtil}.success(list); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import lombok.Data; 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | /** 7 | * ${classInfo.classComment} 8 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 9 | */ 10 | @Data 11 | public class ${classInfo.className} implements Serializable { 12 | private static final long serialVersionUID = 1L; 13 | 14 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 15 | <#list classInfo.fieldList as fieldItem > 16 | /** 17 | * ${fieldItem.fieldComment} 18 | */ 19 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 20 | 21 | 22 | public ${classInfo.className}() { 23 | } 24 | 25 | 26 | } -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentitydto.ftl: -------------------------------------------------------------------------------- 1 | import io.swagger.annotations.ApiModel; 2 | import io.swagger.annotations.ApiModelProperty; 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | /** 9 | * ${classInfo.classComment} 10 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 11 | */ 12 | @Data 13 | @ApiModel("${classInfo.classComment}") 14 | public class ${classInfo.className}DTO { 15 | 16 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 17 | <#list classInfo.fieldList as fieldItem > 18 | @ApiModelProperty("${fieldItem.fieldComment}") 19 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 20 | 21 | 22 | public ${classInfo.className}() { 23 | } 24 | 25 | 26 | } -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/beetlsql/beetlmd.ftl: -------------------------------------------------------------------------------- 1 | sample 2 | === 3 | 4 | select #use("cols")# from ${classInfo.tableName} where #use("condition")# 5 | 6 | cols 7 | === 8 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 9 | <#list classInfo.fieldList as fieldItem > 10 | `${fieldItem.columnName}`<#if fieldItem_has_next>, 11 | 12 | 13 | 14 | updateSample 15 | === 16 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 17 | <#list classInfo.fieldList as fieldItem > 18 | `${fieldItem.columnName}=#${fieldItem.fieldName}#`<#if fieldItem_has_next>, 19 | 20 | 21 | 22 | condition 23 | === 24 | 1 = 1 25 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 26 | <#list classInfo.fieldList as fieldItem > 27 | @if(!isEmpty(${fieldItem.fieldName})){ 28 | and `${fieldItem.columnName}`=#${fieldItem.fieldName}# 29 | @} 30 | 31 | 32 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl: -------------------------------------------------------------------------------- 1 | 2 | import java.util.List; 3 | 4 | /** 5 | * ${classInfo.classComment} 6 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 7 | */ 8 | public interface I${classInfo.className}DAO { 9 | 10 | int add(${classInfo.className} ${classInfo.className?uncap_first}); 11 | 12 | int update(${classInfo.className} ${classInfo.className?uncap_first}); 13 | 14 | int delete(int id); 15 | 16 | ${classInfo.className} findById(int id); 17 | 18 | List<${classInfo.className}> findAllList(Map param); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl: -------------------------------------------------------------------------------- 1 | import org.springframework.beans.factory.annotation.Autowired; 2 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 3 | import org.springframework.jdbc.core.JdbcTemplate; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * ${classInfo.classComment} 10 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 11 | */ 12 | @Repository 13 | public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao{ 14 | 15 | @Autowired 16 | private JdbcTemplate jdbcTemplate; 17 | 18 | @Override 19 | public int add(${classInfo.className} ${classInfo.className?uncap_first}) { 20 | return jdbcTemplate.update("insert into ${classInfo.tableName} (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0>${fieldItem.columnName}<#if fieldItem_has_next>, ) values (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >?<#if fieldItem_has_next>, )", 21 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()<#if fieldItem_has_next>,); 22 | } 23 | 24 | @Override 25 | public int update(${classInfo.className} ${classInfo.className?uncap_first}) { 26 | return jdbcTemplate.update("UPDATE ${classInfo.tableName} SET <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${fieldItem.columnName}=?<#if fieldItem_has_next>," 27 | +" where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break >", 28 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 29 | <#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}(), 30 | <#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0 >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}() 31 | ; 32 | } 33 | 34 | @Override 35 | public int delete(int id) { 36 | return jdbcTemplate.update("DELETE from ${classInfo.tableName} where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break >",id); 37 | } 38 | 39 | @Override 40 | public ${classInfo.className} findById(int id) { 41 | List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.tableName} where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break >", new Object[]{id}, new BeanPropertyRowMapper<${classInfo.className}>(${classInfo.className}.class)); 42 | if(list!=null && list.size()>0){ 43 | ${classInfo.className} ${classInfo.className?uncap_first} = list.get(0); 44 | return ${classInfo.className?uncap_first}; 45 | }else{ 46 | return null; 47 | } 48 | } 49 | 50 | @Override 51 | public List<${classInfo.className}> findAllList(Map params) { 52 | List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.tableName}", new Object[]{}, new BeanPropertyRowMapper<${classInfo.className}>(${classInfo.className}.class)); 53 | if(list!=null && list.size()>0){ 54 | return list; 55 | }else{ 56 | return null; 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-new/dto.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Data 13 | public class ${classInfo.className} implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | @ApiModelProperty("${fieldItem.fieldComment}") 20 | <#if fieldItem.fieldClass == 'LocalDateTime'> 21 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 22 | 23 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 24 | 25 | 26 | public ${classInfo.className}() { 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-new/entity.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Entity 13 | @Data 14 | @Table(name="${classInfo.tableName}") 15 | <#list classInfo.fieldList as fieldItem > 16 | <#if fieldItem.fieldName == 'createTime'> 17 | @EntityListeners(AuditingEntityListener.class) 18 | 19 | 20 | public class ${classInfo.className} implements Serializable { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | @Id 25 | @GeneratedValue(generator = "system-uuid") 26 | @GenericGenerator(name = "system-uuid", strategy = "uuid") 27 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 28 | <#list classInfo.fieldList as fieldItem > 29 | @ApiModelProperty("${fieldItem.fieldComment}") 30 | <#if fieldItem.fieldClass == 'LocalDateTime'> 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 32 | 33 | <#if fieldItem.fieldName == 'createTime'> 34 | @CreatedDate 35 | 36 | <#if fieldItem.fieldName == 'updateTime'> 37 | @LastModifiedDate 38 | 39 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 40 | 41 | 42 | public ${classInfo.className}() { 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-new/jpacontroller-old.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @RestController 23 | @RequestMapping("/${classInfo.className?uncap_first}") 24 | public class ${classInfo.className}Controller { 25 | 26 | @Autowired 27 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 28 | 29 | @ApiOperation("新增或编辑") 30 | @PostMapping("/save") 31 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 32 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 33 | } 34 | 35 | @ApiOperation("删除") 36 | @DeleteMapping("/delete") 37 | public Object delete(String id){ 38 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 39 | if(${classInfo.className?uncap_first}.isPresent()){ 40 | ${classInfo.className?uncap_first}Repository.deleteById(id); 41 | return new Result(true,StatusCode.OK,"删除成功"); 42 | }else{ 43 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 44 | } 45 | } 46 | 47 | @ApiOperation("查询所有") 48 | @GetMapping("/findAll") 49 | public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}) { 50 | 51 | //创建匹配器,需要查询条件请修改此处代码 52 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 53 | 54 | //创建实例 55 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 56 | 57 | return ${classInfo.className?uncap_first}Repository.findAll(example); 58 | } 59 | 60 | 61 | @ApiOperation("查询") 62 | @GetMapping("/find") 63 | public Object find(String id){ 64 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 65 | if(${classInfo.className?uncap_first}.isPresent()){ 66 | return new Result(true,StatusCode.OK,"成功",${classInfo.className?uncap_first}.get()); 67 | }else{ 68 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 69 | } 70 | } 71 | 72 | @ApiOperation("分页查询") 73 | @GetMapping("/list") 74 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 75 | @RequestParam(required = false, defaultValue = "1") int pageNumber, 76 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 77 | 78 | //创建匹配器,需要查询条件请修改此处代码 79 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 80 | 81 | //创建实例 82 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 83 | //分页构造 84 | Pageable pageable = PageRequest.of(pageNumber - 1,pageSize); 85 | 86 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-new/jpacontroller.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @RestController 23 | @RequestMapping("/${classInfo.className?uncap_first}") 24 | public class ${classInfo.className}Controller { 25 | 26 | @Autowired 27 | private ${classInfo.className}Service ${classInfo.className?uncap_first}Service; 28 | 29 | @ApiOperation("新增或编辑") 30 | @PostMapping("/save") 31 | public Object save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){ 32 | return ${classInfo.className?uncap_first}Service.save(${classInfo.className?uncap_first}); 33 | } 34 | 35 | @ApiOperation("删除") 36 | @DeleteMapping("/delete") 37 | public Object delete(String id){ 38 | return ${classInfo.className?uncap_first}Service.delete(id); 39 | } 40 | 41 | @ApiOperation("查询") 42 | @GetMapping("/find") 43 | public Object find(String id){ 44 | return ${classInfo.className?uncap_first}Service.find(id); 45 | } 46 | 47 | <#-- @ApiOperation("查询所有")--> 48 | <#-- @GetMapping("/findAll")--> 49 | <#-- public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}){--> 50 | <#-- return ${classInfo.className?uncap_first}Service.findAll(${classInfo.className?uncap_first});--> 51 | <#-- }--> 52 | 53 | @ApiOperation("分页查询") 54 | @GetMapping("/list") 55 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 56 | @RequestParam(required = false, defaultValue = "1") int pageNumber, 57 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 58 | 59 | return ${classInfo.className?uncap_first}Service.list(${classInfo.className?uncap_first}, pageNumber, pageSize); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-new/repository.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.mapper; 2 | import ${packageName}.entity.${classInfo.className}; 3 | 4 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 5 | <#list classInfo.fieldList as fieldItem > 6 | <#if fieldItem.fieldClass == "Date"> 7 | <#assign importDdate = true /> 8 | 9 | 10 | 11 | import java.util.List; 12 | import org.springframework.data.jpa.repository.JpaRepository; 13 | import org.springframework.data.jpa.repository.Query; 14 | import org.springframework.stereotype.Repository; 15 | 16 | /** 17 | * @Description 18 | * @Author ${authorName} 19 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 20 | **/ 21 | @Repository 22 | public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},String> { 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-new/service.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @Service 23 | @Slf4j 24 | public class ${classInfo.className}Service { 25 | 26 | @Autowired 27 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 28 | 29 | /** 30 | * 新增或编辑 31 | */ 32 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 33 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 34 | } 35 | 36 | /** 37 | * 删除 38 | */ 39 | public Object delete(String id){ 40 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 41 | if(${classInfo.className?uncap_first}.isPresent()){ 42 | ${classInfo.className?uncap_first}Repository.deleteById(id); 43 | return new Result(true,StatusCode.OK,"删除成功"); 44 | }else{ 45 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 46 | } 47 | } 48 | 49 | /** 50 | * 查询 51 | */ 52 | public Object find(String id){ 53 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 54 | if(${classInfo.className?uncap_first}.isPresent()){ 55 | return new Result(true,StatusCode.OK,"成功",${classInfo.className?uncap_first}.get()); 56 | }else{ 57 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 58 | } 59 | } 60 | 61 | <#-- /**--> 62 | <#-- * 查询所有--> 63 | <#-- */--> 64 | <#-- public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}){--> 65 | <#-- //创建匹配器,需要查询条件请修改此处代码--> 66 | <#-- ExampleMatcher matcher = ExampleMatcher.matchingAll();--> 67 | 68 | <#-- //创建实例--> 69 | <#-- Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher);--> 70 | 71 | <#-- return ${classInfo.className?uncap_first}Repository.findAll(example);--> 72 | <#-- }--> 73 | 74 | /** 75 | * 分页查询 76 | */ 77 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 78 | int pageNumber, 79 | int pageSize) { 80 | 81 | //创建匹配器,需要查询条件请修改此处代码 82 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 83 | 84 | //创建实例 85 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 86 | //分页构造 87 | Pageable pageable = PageRequest.of(pageNumber - 1,pageSize); 88 | 89 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-new/vo.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Data 13 | public class ${classInfo.className} implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | @ApiModelProperty("${fieldItem.fieldComment}") 20 | <#if fieldItem.fieldClass == 'LocalDateTime'> 21 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 22 | 23 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 24 | 25 | 26 | public ${classInfo.className}() { 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest-delete/dto.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Data 13 | public class ${classInfo.className}DTO implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | @ApiModelProperty("${fieldItem.fieldComment}") 20 | <#if fieldItem.fieldClass == 'LocalDateTime'> 21 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 22 | 23 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 24 | 25 | 26 | public ${classInfo.className}DTO() { 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest-delete/entity.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Entity 13 | @Data 14 | @Table(name="${classInfo.tableName}") 15 | <#list classInfo.fieldList as fieldItem > 16 | <#if fieldItem.fieldName == 'createTime'> 17 | @EntityListeners(AuditingEntityListener.class) 18 | 19 | 20 | public class ${classInfo.className} implements Serializable { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | @Id 25 | @GeneratedValue(generator = "system-uuid") 26 | @GenericGenerator(name = "system-uuid", strategy = "uuid") 27 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 28 | <#list classInfo.fieldList as fieldItem > 29 | @ApiModelProperty("${fieldItem.fieldComment}") 30 | <#if fieldItem.fieldClass == 'LocalDateTime'> 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 32 | 33 | <#if fieldItem.fieldName == 'createTime'> 34 | @CreatedDate 35 | 36 | <#if fieldItem.fieldName == 'updateTime'> 37 | @LastModifiedDate 38 | 39 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 40 | 41 | 42 | public ${classInfo.className}() { 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest-delete/jpacontroller-old.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @RestController 23 | @RequestMapping("/${classInfo.className?uncap_first}") 24 | public class ${classInfo.className}Controller { 25 | 26 | @Autowired 27 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 28 | 29 | @ApiOperation("新增或编辑") 30 | @PostMapping("/save") 31 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 32 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 33 | } 34 | 35 | @ApiOperation("删除") 36 | @DeleteMapping("/delete") 37 | public Object delete(String id){ 38 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 39 | if(${classInfo.className?uncap_first}.isPresent()){ 40 | ${classInfo.className?uncap_first}Repository.deleteById(id); 41 | return new Result(true,StatusCode.OK,"删除成功"); 42 | }else{ 43 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 44 | } 45 | } 46 | 47 | @ApiOperation("查询所有") 48 | @GetMapping("/findAll") 49 | public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}) { 50 | 51 | //创建匹配器,需要查询条件请修改此处代码 52 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 53 | 54 | //创建实例 55 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 56 | 57 | return ${classInfo.className?uncap_first}Repository.findAll(example); 58 | } 59 | 60 | 61 | @ApiOperation("查询") 62 | @GetMapping("/find") 63 | public Object find(String id){ 64 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 65 | if(${classInfo.className?uncap_first}.isPresent()){ 66 | return new Result(true,StatusCode.OK,"成功",${classInfo.className?uncap_first}.get()); 67 | }else{ 68 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 69 | } 70 | } 71 | 72 | @ApiOperation("分页查询") 73 | @GetMapping("/list") 74 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 75 | @RequestParam(required = false, defaultValue = "1") int pageNumber, 76 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 77 | 78 | //创建匹配器,需要查询条件请修改此处代码 79 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 80 | 81 | //创建实例 82 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 83 | //分页构造 84 | Pageable pageable = PageRequest.of(pageNumber - 1,pageSize); 85 | 86 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest-delete/jpacontroller.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @RestController 23 | @RequestMapping("/${classInfo.className?uncap_first}") 24 | public class ${classInfo.className}Controller { 25 | 26 | @Autowired 27 | private ${classInfo.className}Service ${classInfo.className?uncap_first}Service; 28 | 29 | @ApiOperation("查询所有") 30 | @GetMapping 31 | public Result findAll(){ 32 | return new Result(true, ResultCode.SUCCESS.getCode(), "查询成功", ${classInfo.className?uncap_first}Service.findAll()); 33 | } 34 | 35 | @ApiOperation("通过id查询") 36 | @GetMapping("/{caseId}") 37 | public Result findById(@PathVariable("caseId") String id){ 38 | return new Result(true, ResultCode.SUCCESS.getCode(), "查询成功", ${classInfo.className?uncap_first}Service.findById(id)); 39 | } 40 | 41 | @ApiOperation("新增") 42 | @PostMapping 43 | public Result save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){ 44 | <#list classInfo.fieldList as fieldItem > 45 | <#if fieldItem.fieldName == 'isDelete'> 46 | ${classInfo.className?uncap_first}.setIsDelete("false"); 47 | 48 | 49 | ${classInfo.className?uncap_first}Service.save(${classInfo.className?uncap_first}); 50 | return new Result(true, ResultCode.SUCCESS.getCode(), "添加成功"); 51 | } 52 | 53 | @ApiOperation("更新") 54 | @PutMapping("/{id}") 55 | public Result update(@PathVariable("id") String id, @RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){ 56 | ${classInfo.className?uncap_first}.setId(id); 57 | ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first}); 58 | return new Result(true, ResultCode.SUCCESS.getCode(), "修改成功"); 59 | } 60 | 61 | @ApiOperation("删除") 62 | @DeleteMapping("/{caseId}") 63 | public Result deleteByID(@PathVariable("caseId") String id){ 64 | ${classInfo.className?uncap_first}Service.deleteById(id); 65 | return new Result(true, ResultCode.SUCCESS.getCode(), "删除成功"); 66 | } 67 | 68 | @ApiOperation("批量删除") 69 | @PostMapping("/delete") 70 | public Result delete(@RequestBody List ids){ 71 | ${classInfo.className?uncap_first}Service.delete(ids); 72 | return new Result(true, ResultCode.SUCCESS.getCode(), "删除成功"); 73 | } 74 | 75 | @ApiOperation("分页查询") 76 | @PostMapping("/search/{page}/{size}") 77 | public Result pageQuery(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}, @PathVariable(value = "page") int currentPage, @PathVariable(value = "size") int pageSize) { 78 | Page<${classInfo.className}> pageData = ${classInfo.className?uncap_first}Service.list(${classInfo.className?uncap_first}, currentPage, pageSize); 79 | return new Result(true, ResultCode.SUCCESS.getCode(), "查询成功", 80 | pageData); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest-delete/repository.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.mapper; 2 | import ${packageName}.entity.${classInfo.className}; 3 | 4 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 5 | <#list classInfo.fieldList as fieldItem > 6 | <#if fieldItem.fieldClass == "Date"> 7 | <#assign importDdate = true /> 8 | 9 | 10 | 11 | import java.util.List; 12 | import org.springframework.data.jpa.repository.JpaRepository; 13 | import org.springframework.data.jpa.repository.Query; 14 | import org.springframework.stereotype.Repository; 15 | 16 | /** 17 | * @Description 18 | * @Author ${authorName} 19 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 20 | **/ 21 | @Repository 22 | public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},String> { 23 | 24 | /** 25 | * 批量删除 26 | */ 27 | void deleteByIdIn(List ids); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest-delete/service.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @Service 23 | @Slf4j 24 | public class ${classInfo.className}Service { 25 | 26 | @Autowired 27 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 28 | 29 | 30 | /** 31 | * 查询所有 32 | */ 33 | public Object findAll(){ 34 | return ${classInfo.className?uncap_first}Repository.findAll(); 35 | } 36 | 37 | /** 38 | * 通过id查询 39 | */ 40 | public Object findById(String id){ 41 | return ${classInfo.className?uncap_first}Repository.findById(id).orElse(null); 42 | } 43 | 44 | /** 45 | * 新增 46 | */ 47 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 48 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 49 | } 50 | 51 | /** 52 | * 更新 53 | */ 54 | public void update(${classInfo.className} ${classInfo.className?uncap_first}) { 55 | ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 56 | } 57 | 58 | /** 59 | * 删除 60 | */ 61 | public void deleteById(String id){ 62 | ${classInfo.className?uncap_first}Repository.deleteById(id); 63 | } 64 | 65 | /** 66 | * 查询 67 | */ 68 | public Object find(String id){ 69 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 70 | if(${classInfo.className?uncap_first}.isPresent()){ 71 | return new Result(true,ResultCode.SUCCESS.getCode(),"成功",${classInfo.className?uncap_first}.get()); 72 | }else{ 73 | return new Result(true,ResultCode.ERROR.getCode(),"没有找到该对象"); 74 | } 75 | } 76 | 77 | <#-- /**--> 78 | <#-- * 查询所有--> 79 | <#-- */--> 80 | <#-- public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}){--> 81 | <#-- //创建匹配器,需要查询条件请修改此处代码--> 82 | <#-- ExampleMatcher matcher = ExampleMatcher.matchingAll();--> 83 | 84 | <#-- //创建实例--> 85 | <#-- Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher);--> 86 | 87 | <#-- return ${classInfo.className?uncap_first}Repository.findAll(example);--> 88 | <#-- }--> 89 | 90 | /** 91 | * 分页查询 92 | */ 93 | public Page<${classInfo.className}> list(${classInfo.className} ${classInfo.className?uncap_first}, 94 | int pageNumber, 95 | int pageSize) { 96 | 97 | //创建匹配器,需要查询条件请修改此处代码 98 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 99 | 100 | //创建实例 101 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 102 | //分页构造 103 | Pageable pageable = PageRequest.of(pageNumber - 1,pageSize); 104 | 105 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 106 | } 107 | 108 | /** 109 | * 批量删除 110 | */ 111 | @Transactional 112 | public void delete(List ids) { 113 | ${classInfo.className?uncap_first}Repository.deleteByIdIn(ids); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest-delete/vo.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Data 13 | public class ${classInfo.className}VO implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | @ApiModelProperty("${fieldItem.fieldComment}") 20 | <#if fieldItem.fieldClass == 'LocalDateTime'> 21 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 22 | 23 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 24 | 25 | 26 | public ${classInfo.className}VO() { 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/addparam.ftl: -------------------------------------------------------------------------------- 1 | import com.fasterxml.jackson.annotation.JsonFormat; 2 | import io.swagger.annotations.ApiModelProperty; 3 | import lombok.Data; 4 | import java.io.Serializable; 5 | import java.time.LocalDateTime; 6 | 7 | /** 8 | * @description 9 | * @author ${authorName} 10 | * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | */ 12 | @Data 13 | public class ${classInfo.className}AddParam implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | <#if fieldItem.fieldName == 'id' || fieldItem.fieldName == 'createTime' || fieldItem.fieldName = 'updateTime' || fieldItem.fieldName = 'isDelete' || fieldItem.fieldName = 'createBy' || fieldItem.fieldName = 'updateBy'> 20 | <#continue> 21 | 22 | @ApiModelProperty("${fieldItem.fieldComment}") 23 | <#if fieldItem.fieldClass == 'LocalDateTime'> 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 25 | 26 | <#if fieldItem.fieldClass == 'LocalDate'> 27 | @JsonFormat(pattern = "yyyy-MM-dd") 28 | 29 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 30 | 31 | 32 | public ${classInfo.className}AddParam() { 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/dto.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @description 9 | * @author ${authorName} 10 | * @date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | */ 12 | @Data 13 | public class ${classInfo.className}DTO implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | @ApiModelProperty("${fieldItem.fieldComment}") 20 | <#if fieldItem.fieldClass == 'LocalDateTime'> 21 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 22 | 23 | <#if fieldItem.fieldClass == 'LocalDate'> 24 | @JsonFormat(pattern = "yyyy-MM-dd") 25 | 26 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 27 | 28 | 29 | public ${classInfo.className}DTO() { 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/entity.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description ${classInfo.classComment} 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | */ 12 | @Entity 13 | @Data 14 | @Table(name = "${classInfo.tableName}") 15 | <#list classInfo.fieldList as fieldItem > 16 | <#if fieldItem.fieldName == 'createTime'> 17 | @EntityListeners(AuditingEntityListener.class) 18 | 19 | 20 | @Where(clause="is_delete = false or is_delete is null") // 执行的所有查询将只显示未删除行 21 | public class ${classInfo.className} implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 26 | <#list classInfo.fieldList as fieldItem > 27 | <#if fieldItem.fieldName == 'id'> 28 | @Id 29 | @GeneratedValue(generator = "system-uuid") 30 | @GenericGenerator(name = "system-uuid", strategy = "uuid") 31 | 32 | <#if fieldItem.fieldClass == 'LocalDateTime'> 33 | @ApiModelProperty(value = "${fieldItem.fieldComment}", example = "2019-01-01 22:18:59") 34 | <#else> 35 | @ApiModelProperty(value = "${fieldItem.fieldComment}") 36 | 37 | <#if fieldItem.fieldClass == 'LocalDateTime'> 38 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 39 | 40 | <#if fieldItem.fieldClass == 'LocalDate'> 41 | @JsonFormat(pattern = "yyyy-MM-dd") 42 | 43 | <#if fieldItem.fieldName == 'createTime'> 44 | @CreatedDate 45 | 46 | <#if fieldItem.fieldName == 'updateTime'> 47 | @LastModifiedDate 48 | 49 | @Column(name = "${fieldItem.columnName}") 50 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 51 | 52 | 53 | public ${classInfo.className}() { 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/jpacontroller-old.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @RestController 23 | @RequestMapping("/${classInfo.className?uncap_first}") 24 | public class ${classInfo.className}Controller { 25 | 26 | @Autowired 27 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 28 | 29 | @ApiOperation("新增或编辑") 30 | @PostMapping("/save") 31 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 32 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 33 | } 34 | 35 | @ApiOperation("删除") 36 | @DeleteMapping("/delete") 37 | public Object delete(String id){ 38 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 39 | if(${classInfo.className?uncap_first}.isPresent()){ 40 | ${classInfo.className?uncap_first}Repository.deleteById(id); 41 | return new Result(true,StatusCode.OK,"删除成功"); 42 | }else{ 43 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 44 | } 45 | } 46 | 47 | @ApiOperation("查询所有") 48 | @GetMapping("/findAll") 49 | public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}) { 50 | 51 | //创建匹配器,需要查询条件请修改此处代码 52 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 53 | 54 | //创建实例 55 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 56 | 57 | return ${classInfo.className?uncap_first}Repository.findAll(example); 58 | } 59 | 60 | 61 | @ApiOperation("查询") 62 | @GetMapping("/find") 63 | public Object find(String id){ 64 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 65 | if(${classInfo.className?uncap_first}.isPresent()){ 66 | return new Result(true,StatusCode.OK,"成功",${classInfo.className?uncap_first}.get()); 67 | }else{ 68 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 69 | } 70 | } 71 | 72 | @ApiOperation("分页查询") 73 | @GetMapping("/list") 74 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 75 | @RequestParam(required = false, defaultValue = "1") int pageNumber, 76 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 77 | 78 | //创建匹配器,需要查询条件请修改此处代码 79 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 80 | 81 | //创建实例 82 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 83 | //分页构造 84 | Pageable pageable = PageRequest.of(pageNumber - 1,pageSize); 85 | 86 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/jpacontroller.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @RestController 23 | @RequestMapping("/${classInfo.className?uncap_first}") 24 | @Api(tags = {" "}) 25 | public class ${classInfo.className}Controller { 26 | 27 | @Autowired 28 | private ${classInfo.className}Service ${classInfo.className?uncap_first}Service; 29 | 30 | //@ApiOperation("查询所有") 31 | //@GetMapping 32 | //public Result> findAll(){ 33 | // List<${classInfo.className}> all = ${classInfo.className?uncap_first}Service.findAll(); 34 | // return new Result>(true, ResultCode.SUCCESS.getCode(), "查询成功", all); 35 | //} 36 | 37 | @ApiOperation("通过id查询") 38 | @GetMapping("/{id}") 39 | public Result<${classInfo.className}> findById(@PathVariable("id") String id){ 40 | ${classInfo.className} byId = ${classInfo.className?uncap_first}Service.findById(id); 41 | return new Result<${classInfo.className}>(true, ResultCode.SUCCESS.getCode(), "查询成功", byId); 42 | } 43 | 44 | @ApiOperation("新增") 45 | @PostMapping 46 | public Result<${classInfo.className}> save(@RequestBody ${classInfo.className}AddParam ${classInfo.className?uncap_first}AddParam){ 47 | ${classInfo.className} save = ${classInfo.className?uncap_first}Service.save(${classInfo.className?uncap_first}AddParam); 48 | return new Result<${classInfo.className}>(true, ResultCode.SUCCESS.getCode(), "添加成功", save); 49 | } 50 | 51 | @ApiOperation("更新") 52 | @PutMapping("/{id}") 53 | public Result<${classInfo.className}> update(@PathVariable("id") String id, @RequestBody ${classInfo.className}UpdateParam ${classInfo.className?uncap_first}UpdateParam){ 54 | ${classInfo.className} update = ${classInfo.className?uncap_first}Service.update(id, ${classInfo.className?uncap_first}UpdateParam); 55 | return new Result<${classInfo.className}>(true, ResultCode.SUCCESS.getCode(), "更新成功", update); 56 | } 57 | 58 | @ApiOperation("删除") 59 | @DeleteMapping("/{caseId}") 60 | public Result deleteByID(@PathVariable("caseId") String id){ 61 | ${classInfo.className?uncap_first}Service.deleteById(id); 62 | return new Result(true, ResultCode.SUCCESS.getCode(), "删除成功"); 63 | } 64 | 65 | @ApiOperation("批量删除") 66 | @PostMapping("/delete") 67 | public Result delete(@RequestBody List ids){ 68 | ${classInfo.className?uncap_first}Service.delete(ids); 69 | return new Result(true, ResultCode.SUCCESS.getCode(), "删除成功"); 70 | } 71 | 72 | @ApiOperation("软删除") 73 | @DeleteMapping("/{id}") 74 | public Result deleteByID(@PathVariable("id") String id){ 75 | ${classInfo.className?uncap_first}Service.softDeleteById(id); 76 | return new Result(true, ResultCode.SUCCESS.getCode(), "删除成功"); 77 | } 78 | 79 | @ApiOperation("批量软删除") 80 | @PostMapping("/delete") 81 | public Result delete(@RequestBody List ids){ 82 | ${classInfo.className?uncap_first}Service.delete(ids); 83 | return new Result(true, ResultCode.SUCCESS.getCode(), "删除成功"); 84 | } 85 | 86 | @ApiOperation("分页查询") 87 | @PostMapping("/search/{page}/{size}") 88 | public Result> pageQuery(@RequestBody ${classInfo.className}PageParam ${classInfo.className?uncap_first}PageParam, @PathVariable(value = "page") int currentPage, @PathVariable(value = "size") int pageSize) { 89 | Page<${classInfo.className}> pageData = ${classInfo.className?uncap_first}Service.list(${classInfo.className?uncap_first}PageParam, currentPage, pageSize); 90 | return new Result>(true, ResultCode.SUCCESS.getCode(), "查询成功", pageData); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/pageparam.ftl: -------------------------------------------------------------------------------- 1 | import com.fasterxml.jackson.annotation.JsonFormat; 2 | import io.swagger.annotations.ApiModelProperty; 3 | import lombok.Data; 4 | import java.io.Serializable; 5 | import java.time.LocalDateTime; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Data 13 | public class ${classInfo.className}PageParam implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | <#if fieldItem.fieldName == 'id' || fieldItem.fieldName == 'createTime' || fieldItem.fieldName = 'updateTime' || fieldItem.fieldName = 'isDelete' > 20 | <#continue> 21 | 22 | @ApiModelProperty("${fieldItem.fieldComment}") 23 | <#if fieldItem.fieldClass == 'LocalDateTime'> 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 25 | 26 | <#if fieldItem.fieldClass == 'LocalDate'> 27 | @JsonFormat(pattern = "yyyy-MM-dd") 28 | 29 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 30 | 31 | 32 | public ${classInfo.className}PageParam() { 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/projection.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 投影 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | public interface ${classInfo.className}Projection { 13 | 14 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 15 | <#list classInfo.fieldList as fieldItem > 16 | @ApiModelProperty("${fieldItem.fieldComment}") 17 | <#if fieldItem.fieldClass == 'LocalDateTime'> 18 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 19 | 20 | ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}(); 21 | 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/repository.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.mapper; 2 | import ${packageName}.entity.${classInfo.className}; 3 | 4 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 5 | <#list classInfo.fieldList as fieldItem > 6 | <#if fieldItem.fieldClass == "Date"> 7 | <#assign importDdate = true /> 8 | 9 | 10 | 11 | import java.util.List; 12 | import org.springframework.data.jpa.repository.JpaRepository; 13 | import org.springframework.data.jpa.repository.Query; 14 | import org.springframework.stereotype.Repository; 15 | 16 | /** 17 | * @Description 18 | * @Author ${authorName} 19 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 20 | **/ 21 | @Repository 22 | public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},String> { 23 | 24 | /** 25 | * 批量删除 26 | */ 27 | void deleteByIdIn(List ids); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/service.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @Service 23 | @Slf4j 24 | public class ${classInfo.className}Service { 25 | 26 | @Autowired 27 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 28 | 29 | 30 | /** 31 | * 查询所有 32 | */ 33 | public List<${classInfo.className}> findAll(){ 34 | return ${classInfo.className?uncap_first}Repository.findAll(); 35 | } 36 | 37 | /** 38 | * 通过id查询 39 | */ 40 | public ${classInfo.className} findById(String id){ 41 | return ${classInfo.className?uncap_first}Repository.findById(id).orElse(null); 42 | } 43 | 44 | /** 45 | * 新增 46 | */ 47 | public ${classInfo.className} save(${classInfo.className}AddParam ${classInfo.className?uncap_first}AddParam){ 48 | ${classInfo.className} ${classInfo.className?uncap_first} = new ${classInfo.className}(); 49 | BeanUtils.copyProperties(${classInfo.className?uncap_first}AddParam, ${classInfo.className?uncap_first}); 50 | <#list classInfo.fieldList as fieldItem > 51 | <#if fieldItem.fieldName == 'isDelete'> 52 | ${classInfo.className?uncap_first}.setIsDelete(false); 53 | 54 | 55 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 56 | } 57 | 58 | /** 59 | * 更新 60 | */ 61 | public ${classInfo.className} update(String id, ${classInfo.className}UpdateParam ${classInfo.className?uncap_first}UpdateParam) { 62 | ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Repository.findById(id).get(); 63 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 64 | <#list classInfo.fieldList as fieldItem> 65 | <#if fieldItem.fieldName == 'id' || fieldItem.fieldName == 'createTime' || fieldItem.fieldName = 'updateTime' || fieldItem.fieldName = 'isDelete' > 66 | <#continue> 67 | 68 | if(${classInfo.className?uncap_first}UpdateParam.get${fieldItem.fieldName?cap_first}() != null) { 69 | ${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(${classInfo.className?uncap_first}UpdateParam.get${fieldItem.fieldName?cap_first}()); 70 | } 71 | 72 | 73 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 74 | } 75 | 76 | /** 77 | * 删除 78 | */ 79 | public void deleteById(String id){ 80 | ${classInfo.className?uncap_first}Repository.deleteById(id); 81 | } 82 | 83 | /** 84 | * 软删除 85 | */ 86 | public void softDeleteById(String id){ 87 | ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Repository.findById(id).get(); 88 | ${classInfo.className?uncap_first}.setIsDelete(true); 89 | ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 90 | } 91 | 92 | /** 93 | * 批量删除 94 | */ 95 | @Transactional 96 | public void delete(List ids) { 97 | ${classInfo.className?uncap_first}Repository.deleteByIdIn(ids); 98 | } 99 | 100 | /** 101 | * 批量软删除 102 | */ 103 | @Transactional 104 | public void delete(List ids) { 105 | for (String id : ids) { 106 | Optional<${classInfo.className}> byIdOptional = ${classInfo.className?uncap_first}Repository.findById(id); 107 | if (byIdOptional.isPresent()) { 108 | ${classInfo.className} byId = byIdOptional.get(); 109 | byId.setIsDelete(true); 110 | ${classInfo.className?uncap_first}Repository.save(byId); 111 | } 112 | } 113 | } 114 | 115 | /** 116 | * 查询 117 | */ 118 | public Result find(String id){ 119 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 120 | if(${classInfo.className?uncap_first}.isPresent()){ 121 | return new Result(true,ResultCode.SUCCESS.getCode(),"成功",${classInfo.className?uncap_first}.get()); 122 | }else{ 123 | return new Result(true,ResultCode.FAILED.getCode(),"没有找到该对象"); 124 | } 125 | } 126 | 127 | <#-- /**--> 128 | <#-- * 查询所有--> 129 | <#-- */--> 130 | <#-- public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}){--> 131 | <#-- //创建匹配器,需要查询条件请修改此处代码--> 132 | <#-- ExampleMatcher matcher = ExampleMatcher.matchingAll();--> 133 | 134 | <#-- //创建实例--> 135 | <#-- Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher);--> 136 | 137 | <#-- return ${classInfo.className?uncap_first}Repository.findAll(example);--> 138 | <#-- }--> 139 | 140 | /** 141 | * 分页查询 142 | */ 143 | public Page<${classInfo.className}> list(${classInfo.className}PageParam ${classInfo.className?uncap_first}PageParam, 144 | int pageNumber, 145 | int pageSize) { 146 | 147 | // 创建匹配器,需要查询条件请修改此处代码 148 | //ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("createTime", "updateTime").withMatcher("name", match -> match.contains()); 149 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 150 | 151 | ${classInfo.className} ${classInfo.className?uncap_first} = new ${classInfo.className}(); 152 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 153 | <#list classInfo.fieldList as fieldItem> 154 | <#if fieldItem.fieldName == 'id' || fieldItem.fieldName == 'createTime' || fieldItem.fieldName = 'updateTime' || fieldItem.fieldName = 'isDelete' > 155 | <#continue> 156 | 157 | ${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(${classInfo.className?uncap_first}PageParam.get${fieldItem.fieldName?cap_first}()); 158 | 159 | 160 | 161 | // 创建实例 162 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 163 | // 排序 164 | Sort sort = new Sort(Sort.Direction.DESC, "createTime"); 165 | // 分页构造 166 | Pageable pageable = PageRequest.of(pageNumber - 1, pageSize, sort); 167 | 168 | //// 分页构造 169 | //Pageable pageable = PageRequest.of(pageNumber - 1,pageSize); 170 | 171 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/test.ftl: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @Description 4 | * @Author ${authorName} 5 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 6 | **/ 7 | @RunWith(SpringJUnit4ClassRunner.class) 8 | @SpringBootTest(classes = Application.class) // 需要将 Application.class 替换为你的启动类 9 | @Slf4j 10 | public class ${classInfo.className}Test { 11 | 12 | @Test 13 | public void test${classInfo.className}() { 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/updateparam.ftl: -------------------------------------------------------------------------------- 1 | import com.fasterxml.jackson.annotation.JsonFormat; 2 | import io.swagger.annotations.ApiModelProperty; 3 | import lombok.Data; 4 | import java.io.Serializable; 5 | import java.time.LocalDateTime; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Data 13 | public class ${classInfo.className}UpdateParam implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | <#if fieldItem.fieldName == 'id' || fieldItem.fieldName == 'createTime' || fieldItem.fieldName = 'updateTime'> 20 | <#continue> 21 | 22 | @ApiModelProperty("${fieldItem.fieldComment}") 23 | <#if fieldItem.fieldClass == 'LocalDateTime'> 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 25 | 26 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 27 | 28 | 29 | public ${classInfo.className}UpdateParam() { 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa-rest/vo.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Data 13 | public class ${classInfo.className}VO implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 18 | <#list classInfo.fieldList as fieldItem > 19 | <#-- <#if fieldItem.fieldName == 'id' || fieldItem.fieldName == 'createTime' || fieldItem.fieldName = 'updateTime'>--> 20 | <#-- <#continue>--> 21 | <#-- --> 22 | @ApiModelProperty("${fieldItem.fieldComment}") 23 | <#if fieldItem.fieldClass == 'LocalDateTime'> 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 25 | 26 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 27 | 28 | 29 | public ${classInfo.className}VO() { 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * ${classInfo.classComment} 9 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 10 | */ 11 | @Entity 12 | @Data 13 | @Table(name="${classInfo.tableName}") 14 | public class ${classInfo.className} implements Serializable { 15 | private static final long serialVersionUID = 1L; 16 | @Id 17 | @GeneratedValue 18 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 19 | <#list classInfo.fieldList as fieldItem > 20 | /** 21 | * ${fieldItem.fieldComment} 22 | */ 23 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 24 | 25 | 26 | public ${classInfo.className}() { 27 | } 28 | 29 | 30 | } -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * ${classInfo.classComment} 19 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 20 | */ 21 | @RestController 22 | @RequestMapping("/${classInfo.className?uncap_first}") 23 | public class ${classInfo.className}Controller { 24 | 25 | @Autowired 26 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 27 | 28 | /** 29 | * 新增或编辑 30 | */ 31 | @PostMapping("/save") 32 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 33 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 34 | } 35 | 36 | /** 37 | * 删除 38 | */ 39 | @PostMapping("/delete") 40 | public Object delete(int id){ 41 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 42 | if(${classInfo.className?uncap_first}.isPresent()){ 43 | ${classInfo.className?uncap_first}Repository.deleteById(id); 44 | return ${returnUtil}.success("删除成功"); 45 | }else{ 46 | return ${returnUtil}.error("没有找到该对象"); 47 | } 48 | } 49 | 50 | /** 51 | * 查询 52 | */ 53 | @PostMapping("/find") 54 | public Object find(int id){ 55 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 56 | if(${classInfo.className?uncap_first}.isPresent()){ 57 | return ${returnUtil}.success(${classInfo.className?uncap_first}.get()); 58 | }else{ 59 | return ${returnUtil}.error("没有找到该对象"); 60 | } 61 | } 62 | 63 | /** 64 | * 分页查询 65 | */ 66 | @PostMapping("/list") 67 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 68 | @RequestParam(required = false, defaultValue = "0") int pageNumber, 69 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 70 | 71 | //创建匹配器,需要查询条件请修改此处代码 72 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 73 | 74 | //创建实例 75 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 76 | //分页构造 77 | Pageable pageable = PageRequest.of(pageNumber,pageSize); 78 | 79 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.mapper; 2 | import ${packageName}.entity.${classInfo.className}; 3 | 4 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 5 | <#list classInfo.fieldList as fieldItem > 6 | <#if fieldItem.fieldClass == "Date"> 7 | <#assign importDdate = true /> 8 | 9 | 10 | 11 | import java.util.List; 12 | import org.springframework.data.jpa.repository.JpaRepository; 13 | import org.springframework.data.jpa.repository.Query; 14 | import org.springframework.stereotype.Repository; 15 | 16 | /** 17 | * ${classInfo.classComment} 18 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 19 | */ 20 | @Repository 21 | public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},Integer> { 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.mapper.${classInfo.className}Mapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 8 | import com.baomidou.mybatisplus.core.metadata.IPage; 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * ${classInfo.classComment} 15 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 16 | */ 17 | @RestController 18 | @RequestMapping("/${classInfo.className?uncap_first}") 19 | public class ${classInfo.className}Controller { 20 | 21 | @Autowired 22 | private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper; 23 | 24 | /** 25 | * 新增或编辑 26 | */ 27 | @PostMapping("/save") 28 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 29 | ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id)) 30 | if(${classInfo.className?uncap_first}!=null){ 31 | ${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first}); 32 | }else{ 33 | ${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first}); 34 | } 35 | return ${returnUtil}.success(${classInfo.className?uncap_first}); 36 | } 37 | 38 | /** 39 | * 删除 40 | */ 41 | @PostMapping("/delete") 42 | public Object delete(int id){ 43 | ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id)) 44 | if(${classInfo.className?uncap_first}!=null){ 45 | return ${returnUtil}.success(${classInfo.className?uncap_first}); 46 | }else{ 47 | return ${returnUtil}.error("没有找到该对象"); 48 | } 49 | } 50 | 51 | /** 52 | * 查询 53 | */ 54 | @PostMapping("/find") 55 | public Object find(int id){ 56 | ${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id)) 57 | if(${classInfo.className?uncap_first}!=null){ 58 | return ${returnUtil}.success(${classInfo.className?uncap_first}); 59 | }else{ 60 | return ${returnUtil}.error("没有找到该对象"); 61 | } 62 | } 63 | 64 | /** 65 | * 分页查询 66 | */ 67 | @PostMapping("/list") 68 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 69 | @RequestParam(required = false, defaultValue = "0") int pageNumber, 70 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 71 | //分页构造器 72 | Page<${classInfo.className}> page = new Page<${classInfo.className}>(pageNumber,pageSize); 73 | //条件构造器 74 | QueryWrapper<${classInfo.className}> queryWrapperw = new QueryWrapper<${classInfo.className}>(${classInfo.className?uncap_first}); 75 | //执行分页 76 | IPage<${classInfo.className}> pageList = certPersonMapper.selectPage(page, queryWrapperw); 77 | //返回结果 78 | return ${returnUtil}.success(pageList); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.mapper; 2 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 3 | import org.springframework.stereotype.Repository; 4 | 5 | /** 6 | * ${classInfo.classComment} 7 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 8 | */ 9 | @Repository 10 | public interface ${classInfo.className}Mapper extends BaseMapper<${classInfo.className}> { 11 | 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl: -------------------------------------------------------------------------------- 1 | import org.springframework.stereotype.Controller; 2 | import org.springframework.web.bind.annotation.RequestMapping; 3 | import org.springframework.web.bind.annotation.RequestParam; 4 | import org.springframework.web.bind.annotation.ResponseBody; 5 | 6 | import javax.annotation.Resource; 7 | import javax.servlet.http.HttpServletRequest; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * ${classInfo.classComment} 13 | * @author ${authorName} 14 | * @date ${.now?string('yyyy/MM/dd')} 15 | */ 16 | @RestController 17 | @RequestMapping(value = "/${classInfo.className}") 18 | public class ${classInfo.className}Controller { 19 | 20 | @Resource 21 | private ${classInfo.className}Service ${classInfo.className?uncap_first}Service; 22 | 23 | /** 24 | * [新增] 25 | * @author ${authorName} 26 | * @date ${.now?string('yyyy/MM/dd')} 27 | **/ 28 | @RequestMapping("/insert") 29 | public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}){ 30 | return ${classInfo.className?uncap_first}Service.insert(${classInfo.className?uncap_first}); 31 | } 32 | 33 | /** 34 | * [刪除] 35 | * @author ${authorName} 36 | * @date ${.now?string('yyyy/MM/dd')} 37 | **/ 38 | @RequestMapping("/delete") 39 | public ReturnT delete(int id){ 40 | return ${classInfo.className?uncap_first}Service.delete(id); 41 | } 42 | 43 | /** 44 | * [更新] 45 | * @author ${authorName} 46 | * @date ${.now?string('yyyy/MM/dd')} 47 | **/ 48 | @RequestMapping("/update") 49 | public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}){ 50 | return ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first}); 51 | } 52 | 53 | /** 54 | * [查询] 根据主键 id 查询 55 | * @author ${authorName} 56 | * @date ${.now?string('yyyy/MM/dd')} 57 | **/ 58 | @RequestMapping("/load") 59 | public ReturnT load(int id){ 60 | return ${classInfo.className?uncap_first}Service.load(id); 61 | } 62 | 63 | @RequestMapping("/pageList") 64 | public Map pageList(@RequestParam(required = false, defaultValue = "0") int offset, 65 | @RequestParam(required = false, defaultValue = "10") int pagesize) { 66 | return ${classInfo.className?uncap_first}Service.pageList(offset, pagesize); 67 | } 68 | 69 | /** 70 | * [查询] 分页查询 71 | * @author ${authorName} 72 | * @date ${.now?string('yyyy/MM/dd')} 73 | **/ 74 | @RequestMapping("/pageList/{page}/{size}") 75 | public Result> pageList(@RequestBody ${classInfo.className}PageParam ${classInfo.className?uncap_first}PageParam, @PathVariable(value = "page") int currentPage, @PathVariable(value = "size") int pageSize) { 76 | return Result.success(${classInfo.className?uncap_first}Service.pageList(${classInfo.className?uncap_first}PageParam, currentPage, pageSize)); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl: -------------------------------------------------------------------------------- 1 | import org.apache.ibatis.annotations.Param; 2 | import org.apache.ibatis.annotations.Mapper; 3 | import org.springframework.stereotype.Repository; 4 | import java.util.List; 5 | 6 | /** 7 | * ${classInfo.classComment} 8 | * @author ${authorName} 9 | * @date ${.now?string('yyyy/MM/dd')} 10 | */ 11 | @Mapper 12 | @Repository 13 | public interface ${classInfo.className}Mapper { 14 | 15 | /** 16 | * [新增] 17 | * @author ${authorName} 18 | * @date ${.now?string('yyyy/MM/dd')} 19 | **/ 20 | int insert(${classInfo.className} ${classInfo.className?uncap_first}); 21 | 22 | /** 23 | * [刪除] 24 | * @author ${authorName} 25 | * @date ${.now?string('yyyy/MM/dd')} 26 | **/ 27 | int delete(int id); 28 | 29 | /** 30 | * [更新] 31 | * @author ${authorName} 32 | * @date ${.now?string('yyyy/MM/dd')} 33 | **/ 34 | int update(${classInfo.className} ${classInfo.className?uncap_first}); 35 | 36 | /** 37 | * [查询] 根据主键 id 查询 38 | * @author ${authorName} 39 | * @date ${.now?string('yyyy/MM/dd')} 40 | **/ 41 | ${classInfo.className} load(int id); 42 | 43 | /** 44 | * [查询] 分页查询 45 | * @author ${authorName} 46 | * @date ${.now?string('yyyy/MM/dd')} 47 | **/ 48 | List<${classInfo.className}> pageList(int offset,int pagesize); 49 | 50 | /** 51 | * [查询] 分页查询 52 | * @author ${authorName} 53 | * @date ${.now?string('yyyy/MM/dd')} 54 | **/ 55 | List<${classInfo.className}> pageList(@Param("${classInfo.className?uncap_first}PageParam") ${classInfo.className}PageParam ${classInfo.className?uncap_first}); 56 | 57 | /** 58 | * [查询] 分页查询 count 59 | * @author ${authorName} 60 | * @date ${.now?string('yyyy/MM/dd')} 61 | **/ 62 | int pageListCount(int offset,int pagesize); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import java.util.Date; 3 | import java.util.List; 4 | 5 | /** 6 | * ${classInfo.classComment} 7 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 8 | */ 9 | public class ${classInfo.className} implements Serializable { 10 | private static final long serialVersionUID = 1L; 11 | 12 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 13 | <#list classInfo.fieldList as fieldItem > 14 | /** 15 | * ${fieldItem.fieldComment} 16 | */ 17 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 18 | 19 | 20 | 21 | 22 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 23 | public ${classInfo.className}() { 24 | } 25 | 26 | <#list classInfo.fieldList as fieldItem> 27 | public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() { 28 | return ${fieldItem.fieldName}; 29 | } 30 | 31 | public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) { 32 | this.${fieldItem.fieldName} = ${fieldItem.fieldName}; 33 | } 34 | 35 | 36 | 37 | } -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis/mybatis.ftl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 8 | <#list classInfo.fieldList as fieldItem > 9 | 10 | 11 | 12 | 13 | 14 | 15 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 16 | <#list classInfo.fieldList as fieldItem > 17 | ${fieldItem.columnName}<#if fieldItem_has_next>, 18 | 19 | 20 | 21 | 22 | 23 | INSERT INTO ${classInfo.tableName} 24 | 25 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 26 | <#list classInfo.fieldList as fieldItem > 27 | <#if fieldItem.columnName != "id" > 28 | ${r""} 29 | ${fieldItem.columnName}<#if fieldItem_has_next>, 30 | ${r""} 31 | 32 | 33 | 34 | 35 | 36 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 37 | <#list classInfo.fieldList as fieldItem > 38 | <#if fieldItem.columnName != "id" > 39 | <#--<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime" > 40 | ${r""} 41 | NOW()<#if fieldItem_has_next>, 42 | ${r""} 43 | <#else>--> 44 | ${r""} 45 | ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>, 46 | ${r""} 47 | <#----> 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | DELETE FROM ${classInfo.tableName} 56 | WHERE id = ${r"#{id}"} 57 | 58 | 59 | 60 | UPDATE ${classInfo.tableName} 61 | 62 | <#list classInfo.fieldList as fieldItem > 63 | <#if fieldItem.columnName != "id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" > 64 | ${r""}${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,${r""} 65 | 66 | 67 | 68 | WHERE id = ${r"#{"}id${r"}"} 69 | 70 | 71 | 72 | 77 | 78 | 83 | 84 | 112 | 113 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl: -------------------------------------------------------------------------------- 1 | import java.util.Map; 2 | 3 | /** 4 | * ${classInfo.classComment} 5 | * @author ${authorName} 6 | * @date ${.now?string('yyyy/MM/dd')} 7 | */ 8 | public interface ${classInfo.className}Service { 9 | 10 | /** 11 | * 新增 12 | */ 13 | public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}); 14 | 15 | /** 16 | * 删除 17 | */ 18 | public ReturnT delete(int id); 19 | 20 | /** 21 | * 更新 22 | */ 23 | public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}); 24 | 25 | /** 26 | * 根据主键 id 查询 27 | */ 28 | public ${classInfo.className} load(int id); 29 | 30 | /** 31 | * 分页查询 32 | */ 33 | public Map pageList(int offset, int pagesize); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl: -------------------------------------------------------------------------------- 1 | import org.springframework.stereotype.Service; 2 | 3 | import javax.annotation.Resource; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * ${classInfo.classComment} 11 | * @author ${authorName} 12 | * @date ${.now?string('yyyy/MM/dd')} 13 | */ 14 | @Service 15 | public class ${classInfo.className}ServiceImpl implements ${classInfo.className}Service { 16 | 17 | @Resource 18 | private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper; 19 | 20 | 21 | @Override 22 | public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}) { 23 | 24 | // valid 25 | if (${classInfo.className?uncap_first} == null) { 26 | return new ReturnT(ReturnT.FAIL_CODE, "必要参数缺失"); 27 | } 28 | 29 | ${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first}); 30 | return ReturnT.SUCCESS; 31 | } 32 | 33 | 34 | @Override 35 | public ReturnT delete(int id) { 36 | int ret = ${classInfo.className?uncap_first}Mapper.delete(id); 37 | return ret>0?ReturnT.SUCCESS:ReturnT.FAIL; 38 | } 39 | 40 | 41 | @Override 42 | public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}) { 43 | int ret = ${classInfo.className?uncap_first}Mapper.update(${classInfo.className?uncap_first}); 44 | return ret>0?ReturnT.SUCCESS:ReturnT.FAIL; 45 | } 46 | 47 | 48 | @Override 49 | public ${classInfo.className} load(int id) { 50 | return ${classInfo.className?uncap_first}Mapper.load(id); 51 | } 52 | 53 | 54 | @Override 55 | public Map pageList(int offset, int pagesize) { 56 | 57 | List<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.pageList(offset, pagesize); 58 | int totalCount = ${classInfo.className?uncap_first}Mapper.pageListCount(offset, pagesize); 59 | 60 | // result 61 | Map result = new HashMap(); 62 | result.put("pageList", pageList); 63 | result.put("totalCount", totalCount); 64 | 65 | return result; 66 | } 67 | 68 | public PageInfo<${classInfo.className}> pageList(${classInfo.className}PageParam ${classInfo.className?uncap_first}PageParam, int offset, int pageSize) { 69 | PageHelper.startPage(offset, pageSize); 70 | List<${classInfo.className}> ${classInfo.className?uncap_first}List = ${classInfo.className?uncap_first}Mapper.pageList(${classInfo.className?uncap_first}PageParam); 71 | List<${classInfo.className?uncap_first}VO> ${classInfo.className?uncap_first}VOList = new ArrayList<>(); 72 | for (${classInfo.className} ${classInfo.className?uncap_first} :${classInfo.className?uncap_first}List) { 73 | ${classInfo.className}VO ${classInfo.className?uncap_first}VO = new ${classInfo.className?uncap_first}VO(); 74 | BeanUtils.copyProperties(${classInfo.className?uncap_first}, ${classInfo.className?uncap_first}VO); 75 | caseInfoVOList.add(${classInfo.className?uncap_first}VO); 76 | } 77 | PageInfo pageResult = new PageInfo<>(${classInfo.className?uncap_first}List); 78 | pageResult.setList(${classInfo.className?uncap_first}VOList); 79 | return pageResult; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/restful-jpa/entity.ftl: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import javax.persistence.*; 3 | import lombok.Data; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | /** 8 | * @Description 9 | * @Author ${authorName} 10 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 11 | **/ 12 | @Entity 13 | @Data 14 | @Table(name="${classInfo.tableName}") 15 | public class ${classInfo.className} implements Serializable { 16 | private static final long serialVersionUID = 1L; 17 | 18 | @Id 19 | @GeneratedValue(generator = "system-uuid") 20 | @GenericGenerator(name = "system-uuid", strategy = "uuid") 21 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 22 | <#list classInfo.fieldList as fieldItem > 23 | @ApiModelProperty("${fieldItem.fieldComment}") 24 | private ${fieldItem.fieldClass} ${fieldItem.fieldName}; 25 | 26 | 27 | public ${classInfo.className}() { 28 | } 29 | 30 | 31 | } -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/restful-jpa/jpacontroller.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @RestController 23 | @RequestMapping("/${classInfo.className?uncap_first}") 24 | public class ${classInfo.className}Controller { 25 | 26 | @Autowired 27 | private ${classInfo.className}Service ${classInfo.className?uncap_first}Service; 28 | 29 | @ApiOperation("新增") 30 | @PostMapping("/save") 31 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 32 | return ${classInfo.className?uncap_first}Service.save(${classInfo.className?uncap_first}); 33 | } 34 | 35 | @ApiOperation("删除") 36 | @DeleteMapping("/delete") 37 | public Object delete(String id){ 38 | return ${classInfo.className?uncap_first}Service.delete(id); 39 | } 40 | 41 | @ApiOperation("查询") 42 | @GetMapping("/find") 43 | public Object find(String id){ 44 | return ${classInfo.className?uncap_first}Service.find(id); 45 | } 46 | 47 | @ApiOperation("查询") 48 | @GetMapping("/findAll") 49 | public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}){ 50 | return ${classInfo.className?uncap_first}Service.findAll(${classInfo.className?uncap_first}); 51 | } 52 | 53 | @ApiOperation("分页查询") 54 | @GetMapping("/list") 55 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 56 | @RequestParam(required = false, defaultValue = "1") int pageNumber, 57 | @RequestParam(required = false, defaultValue = "10") int pageSize) { 58 | 59 | return ${classInfo.className?uncap_first}Service.list(${classInfo.className?uncap_first}, pageNumber, pageSize); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/restful-jpa/repository.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.mapper; 2 | import ${packageName}.entity.${classInfo.className}; 3 | 4 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 5 | <#list classInfo.fieldList as fieldItem > 6 | <#if fieldItem.fieldClass == "Date"> 7 | <#assign importDdate = true /> 8 | 9 | 10 | 11 | import java.util.List; 12 | import org.springframework.data.jpa.repository.JpaRepository; 13 | import org.springframework.data.jpa.repository.Query; 14 | import org.springframework.stereotype.Repository; 15 | 16 | /** 17 | * @Description 18 | * @Author ${authorName} 19 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 20 | **/ 21 | @Repository 22 | public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},String> { 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/restful-jpa/service.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}.controller; 2 | 3 | import ${packageName}.entity.${classInfo.className}; 4 | import ${packageName}.repository.${classInfo.className}Repository; 5 | import org.springframework.data.domain.Example; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.data.domain.ExampleMatcher; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @Description 19 | * @Author ${authorName} 20 | * @Date ${.now?string('yyyy-MM-dd HH:mm:ss')} 21 | **/ 22 | @Service 23 | @Slf4j 24 | public class ${classInfo.className}Service { 25 | 26 | @Autowired 27 | private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository; 28 | 29 | /** 30 | * 新增或编辑 31 | */ 32 | public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ 33 | return ${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}); 34 | } 35 | 36 | /** 37 | * 删除 38 | */ 39 | public Object delete(String id){ 40 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 41 | if(${classInfo.className?uncap_first}.isPresent()){ 42 | ${classInfo.className?uncap_first}Repository.deleteById(id); 43 | return new Result(true,StatusCode.OK,"删除成功"); 44 | }else{ 45 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 46 | } 47 | } 48 | 49 | /** 50 | * 查询 51 | */ 52 | public Object find(String id){ 53 | Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id); 54 | if(${classInfo.className?uncap_first}.isPresent()){ 55 | return new Result(true,StatusCode.OK,"成功",${classInfo.className?uncap_first}.get()); 56 | }else{ 57 | return new Result(true,StatusCode.ERROR,"没有找到该对象"); 58 | } 59 | } 60 | 61 | /** 62 | * 查询所有 63 | */ 64 | public Object findAll(${classInfo.className} ${classInfo.className?uncap_first}){ 65 | //创建匹配器,需要查询条件请修改此处代码 66 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 67 | 68 | //创建实例 69 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 70 | 71 | return ${classInfo.className?uncap_first}Repository.findAll(example); 72 | } 73 | 74 | 75 | 76 | /** 77 | * 分页查询 78 | */ 79 | public Object list(${classInfo.className} ${classInfo.className?uncap_first}, 80 | int pageNumber, 81 | int pageSize) { 82 | 83 | //创建匹配器,需要查询条件请修改此处代码 84 | ExampleMatcher matcher = ExampleMatcher.matchingAll(); 85 | 86 | //创建实例 87 | Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher); 88 | //分页构造 89 | Pageable pageable = PageRequest.of(pageNumber - 1,pageSize); 90 | 91 | return ${classInfo.className?uncap_first}Repository.findAll(example, pageable); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl: -------------------------------------------------------------------------------- 1 |
2 | 3 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 4 | <#list classInfo.fieldList as fieldItem > 5 |
6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 |
14 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/ui/element-ui.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | ${classInfo.classComment} 7 | 提交 8 | 返回 9 |
10 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 11 | <#list classInfo.fieldList as fieldItem > 12 | 13 | 14 | 15 | 16 | 17 |
18 |
-------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/ui/swagger-ui.ftl: -------------------------------------------------------------------------------- 1 | @ApiOperation(value = "${classInfo.classComment}", notes = "${classInfo.classComment}") 2 | @ApiImplicitParams({ 3 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 4 | <#list classInfo.fieldList as fieldItem > 5 | @ApiImplicitParam(name = "${fieldItem.fieldName}", value = "${fieldItem.fieldComment}", required = false, dataType = "${fieldItem.fieldClass}")<#if fieldItem_has_next>, 6 | 7 | 8 | } 9 | ) 10 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/code-generator/util/util.ftl: -------------------------------------------------------------------------------- 1 | /** 2 | * ${classInfo.classComment}表所有属性Get Set 3 | * @author ${authorName} ${.now?string('yyyy-MM-dd')} 4 | */ 5 | 6 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 7 | <#list classInfo.fieldList as fieldItem> 8 | // ${fieldItem.fieldComment} 9 | ${fieldItem.fieldClass} ${fieldItem.fieldName} = ${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}(); 10 | 11 | 12 | <#list classInfo.fieldList as fieldItem> 13 | // ${fieldItem.fieldComment} 14 | ${classInfo.className?uncap_first}.set${fieldItem.fieldName?cap_first}(); 15 | 16 | 17 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/common/common-import.ftl: -------------------------------------------------------------------------------- 1 | <#macro commonStyle> 2 | 3 | <#-- favicon --> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | <#macro commonScript> 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | <#macro commonFooter > 49 | 60 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/index.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SQL转Java JPA、MYBATIS实现类代码生成平台 6 | 7 | <#import "common/common-import.ftl" as netCommon> 8 | <@netCommon.commonStyle /> 9 | 10 | <@netCommon.commonScript /> 11 | <#----> 12 | 104 | 105 | 106 | 107 | 108 | 109 |
110 |
111 |

Spring Boot Code Generator!

112 |

113 | 基于SpringBoot2+Freemarker的代码生成器,用DDL SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码,支持mysql/oracle/pgsql三大数据库。以释放双手为目的。 114 |

115 |
116 |
117 | 作者名称 118 |
119 | 120 |
121 | 包名路径 122 |
123 | 124 |
125 |
126 |
127 | 返回封装 128 |
129 | 130 |
131 |
139 |

140 |
141 | 142 |
143 | 154 | 168 |
169 | 170 |
171 | 182 | 183 | 195 |
196 | 197 |
198 | 209 | 221 |
222 |
223 | 234 | 247 |
248 |
249 | 259 | 269 |
270 |
271 | 284 | 304 |
305 |
306 | 307 |
308 |
309 | 310 |
311 | 312 |
313 | 321 |
322 | 323 | 324 | 325 | 326 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/sql-generator/pgsql/delete.ftl: -------------------------------------------------------------------------------- 1 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 2 | DELETE 3 | FROM 4 | ${classInfo.tableName} 5 | WHERE 6 | <#list classInfo.fieldList as fieldItem > 7 | ${fieldItem.columnName} = ''<#if fieldItem_has_next>, 8 | ; 9 | 10 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/sql-generator/pgsql/drop.ftl: -------------------------------------------------------------------------------- 1 | DROP TABLE ${classInfo.tableName}; 2 | 3 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/sql-generator/pgsql/insert.ftl: -------------------------------------------------------------------------------- 1 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 2 | INSERT INTO ${classInfo.tableName} ( <#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>, ) 3 | VALUES 4 | ( 5 | <#list classInfo.fieldList as fieldItem > 6 | ''<#if fieldItem_has_next>, 7 | 8 | ); 9 | 10 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/sql-generator/pgsql/select.ftl: -------------------------------------------------------------------------------- 1 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 2 | SELECT 3 | <#list classInfo.fieldList as fieldItem > 4 | ${fieldItem.columnName}<#if fieldItem_has_next>, 5 | 6 | FROM 7 | ${classInfo.tableName} 8 | WHERE 9 | <#list classInfo.fieldList as fieldItem > 10 | <#if fieldItem_index != 0>AND ${fieldItem.columnName} = '' 11 | ; 12 | 13 | 14 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/sql-generator/pgsql/sql.ftl: -------------------------------------------------------------------------------- 1 | <#--CREATE TABLE "public"."${tableInfo.tableName}" (--> 2 | <#--"id" varchar(255) NOT NULL,--> 3 | 4 | <#--<#if tableInfo.fieldList?exists && tableInfo.fieldList?size gt 0>--> 5 | <#-- <#list tableInfo.fieldList as fieldName >--> 6 | <#-- "${fieldName}" varchar(255),--> 7 | <#-- --> 8 | <#----> 9 | 10 | <#--CONSTRAINT "${tableInfo.tableName}_pkey" PRIMARY KEY ("id")--> 11 | <#--);--> 12 | 13 | <#--ALTER TABLE "public"."${tableInfo.tableName}"--> 14 | <#--OWNER TO "postgres";--> 15 | 16 | <#--COMMENT ON COLUMN "public"."${tableInfo.tableName}"."id" IS '主键';--> 17 | -------------------------------------------------------------------------------- /generator-web/src/main/resources/templates/sql-generator/pgsql/update.ftl: -------------------------------------------------------------------------------- 1 | <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> 2 | UPDATE ${classInfo.tableName} 3 | SET 4 | <#list classInfo.fieldList as fieldItem > 5 | ${fieldItem.columnName} = ''<#if fieldItem_has_next>, 6 | 7 | WHERE 8 | <#list classInfo.fieldList as fieldItem > 9 | ${fieldItem.columnName} = ''<#if fieldItem_has_next>, 10 | ; 11 | 12 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.softdev.system 7 | SpringBootCodeGenerator 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.1.6.RELEASE 15 | 16 | 17 | 18 | generator-web 19 | 20 | 21 | 22 | 23 | 24 | UTF-8 25 | 26 | 1.8 27 | 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-web 34 | 35 | 36 | 37 | com.alibaba 38 | fastjson 39 | 1.2.44 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-configuration-processor 46 | true 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-devtools 54 | 2.0.4.RELEASE 55 | 56 | 57 | 58 | 59 | org.springframework 60 | springloaded 61 | 1.2.8.RELEASE 62 | 63 | 64 | 65 | 66 | 67 | cn.hutool 68 | hutool-all 69 | 4.1.12 70 | 71 | 72 | 73 | 74 | org.projectlombok 75 | lombok 76 | 1.18.2 77 | 78 | 79 | 80 | 84 | 85 | 89 | 90 | 91 | com.alibaba 92 | druid 93 | 1.1.3 94 | 95 | 96 | 97 | log4j 98 | log4j 99 | 1.2.16 100 | 101 | 102 | 103 | 104 | junit 105 | junit 106 | test 107 | 108 | 109 | 113 | 114 | 115 | 116 | org.apache.commons 117 | commons-lang3 118 | 3.8 119 | 120 | 121 | 122 | 123 | org.springframework.boot 124 | spring-boot-starter-freemarker 125 | 126 | 127 | 128 | 129 | javax.xml.bind 130 | jaxb-api 131 | 2.3.0 132 | 133 | 134 | com.sun.xml.bind 135 | jaxb-impl 136 | 2.3.0 137 | 138 | 139 | com.sun.xml.bind 140 | jaxb-core 141 | 2.3.0 142 | 143 | 144 | javax.activation 145 | activation 146 | 1.1.1 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | src/main/java 157 | 158 | **/*.properties 159 | **/*.xml 160 | 161 | false 162 | 163 | 164 | src/main/resources 165 | 166 | 167 | 168 | 169 | org.apache.maven.plugins 170 | maven-compiler-plugin 171 | 3.1 172 | 173 | true 174 | javac 175 | 1.8 176 | 1.8 177 | UTF-8 178 | 1.8 179 | true 180 | true 181 | 182 | 183 | 184 | org.codehaus.plexus 185 | plexus-compiler-eclipse 186 | 2.2 187 | 188 | 189 | 190 | 191 | org.apache.maven.plugins 192 | maven-resources-plugin 193 | 3.0.1 194 | 195 | 196 | true 197 | 198 | 199 | 200 | org.apache.maven.plugins 201 | maven-war-plugin 202 | 2.1.1 203 | 204 | false 205 | upload/** 206 | 207 | 208 | 209 | org.springframework.boot 210 | spring-boot-maven-plugin 211 | 2.0.4.RELEASE 212 | 213 | 214 | 215 | repackage 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | spring-milestones 227 | Spring Milestones 228 | https://repo.spring.io/libs-milestone 229 | 230 | false 231 | 232 | 233 | 234 | 235 | --------------------------------------------------------------------------------