From 9ec0d0fe035de76fcd1d9f6e9f635d97f86265eb Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期四, 29 五月 2025 11:07:58 +0800 Subject: [PATCH] 代码生成 --- /dev/null | 84 --------- ruoyi-admin/src/main/resources/templates/controller.Java.ftl | 40 ++++ ruoyi-admin/src/main/resources/templates/entity.java.ftl | 44 ++++ ruoyi-admin/src/main/resources/templates/mapper.xml.ftl | 39 ++++ ruoyi-admin/pom.xml | 12 + ruoyi-admin/src/main/resources/templates/serviceImpl.java.ftl | 30 +++ ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java | 6 basic-server/pom.xml | 38 ++++ ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java | 162 ++++++++++++++++++ pom.xml | 47 ++++ 10 files changed, 411 insertions(+), 91 deletions(-) diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 8564f29..0000000 --- a/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2018 RuoYi - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 274d769..0000000 --- a/README.md +++ /dev/null @@ -1,95 +0,0 @@ -<p align="center"> - <img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png"> -</p> -<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.8.9</h1> -<h4 align="center">鍩轰簬SpringBoot+Vue鍓嶅悗绔垎绂荤殑Java蹇�熷紑鍙戞鏋�</h4> -<p align="center"> - <a href="https://gitee.com/y_project/RuoYi-Vue/stargazers"><img src="https://gitee.com/y_project/RuoYi-Vue/badge/star.svg?theme=dark"></a> - <a href="https://gitee.com/y_project/RuoYi-Vue"><img src="https://img.shields.io/badge/RuoYi-v3.8.9-brightgreen.svg"></a> - <a href="https://gitee.com/y_project/RuoYi-Vue/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a> -</p> - -## 骞冲彴绠�浠� - -鑻ヤ緷鏄竴濂楀叏閮ㄥ紑婧愮殑蹇�熷紑鍙戝钩鍙帮紝姣棤淇濈暀缁欎釜浜哄強浼佷笟鍏嶈垂浣跨敤銆� - -* 鍓嶇閲囩敤Vue銆丒lement UI銆� -* 鍚庣閲囩敤Spring Boot銆丼pring Security銆丷edis & Jwt銆� -* 鏉冮檺璁よ瘉浣跨敤Jwt锛屾敮鎸佸缁堢璁よ瘉绯荤粺銆� -* 鏀寔鍔犺浇鍔ㄦ�佹潈闄愯彍鍗曪紝澶氭柟寮忚交鏉炬潈闄愭帶鍒躲�� -* 楂樻晥鐜囧紑鍙戯紝浣跨敤浠g爜鐢熸垚鍣ㄥ彲浠ヤ竴閿敓鎴愬墠鍚庣浠g爜銆� -* 鎻愪緵浜嗘妧鏈爤锛圼Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev)锛夌増鏈琜RuoYi-Vue3](https://gitcode.com/yangzongzhuan/RuoYi-Vue3)锛屼繚鎸佸悓姝ユ洿鏂般�� -* 鎻愪緵浜嗗崟搴旂敤鐗堟湰[RuoYi-Vue-fast](https://gitcode.com/yangzongzhuan/RuoYi-Vue-fast)锛孫racle鐗堟湰[RuoYi-Vue-Oracle](https://gitcode.com/yangzongzhuan/RuoYi-Vue-Oracle)锛屼繚鎸佸悓姝ユ洿鏂般�� -* 涓嶅垎绂荤増鏈紝璇风Щ姝RuoYi](https://gitee.com/y_project/RuoYi)锛屽井鏈嶅姟鐗堟湰锛岃绉绘[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud) -* 闃块噷浜戞姌鎵e満锛歔鐐规垜杩涘叆](http://aly.ruoyi.vip)锛岃吘璁簯绉掓潃鍦猴細[鐐规垜杩涘叆](http://txy.ruoyi.vip) - -## 鍐呯疆鍔熻兘 - -1. 鐢ㄦ埛绠$悊锛氱敤鎴锋槸绯荤粺鎿嶄綔鑰咃紝璇ュ姛鑳戒富瑕佸畬鎴愮郴缁熺敤鎴烽厤缃�� -2. 閮ㄩ棬绠$悊锛氶厤缃郴缁熺粍缁囨満鏋勶紙鍏徃銆侀儴闂ㄣ�佸皬缁勶級锛屾爲缁撴瀯灞曠幇鏀寔鏁版嵁鏉冮檺銆� -3. 宀椾綅绠$悊锛氶厤缃郴缁熺敤鎴锋墍灞炴媴浠昏亴鍔°�� -4. 鑿滃崟绠$悊锛氶厤缃郴缁熻彍鍗曪紝鎿嶄綔鏉冮檺锛屾寜閽潈闄愭爣璇嗙瓑銆� -5. 瑙掕壊绠$悊锛氳鑹茶彍鍗曟潈闄愬垎閰嶃�佽缃鑹叉寜鏈烘瀯杩涜鏁版嵁鑼冨洿鏉冮檺鍒掑垎銆� -6. 瀛楀吀绠$悊锛氬绯荤粺涓粡甯镐娇鐢ㄧ殑涓�浜涜緝涓哄浐瀹氱殑鏁版嵁杩涜缁存姢銆� -7. 鍙傛暟绠$悊锛氬绯荤粺鍔ㄦ�侀厤缃父鐢ㄥ弬鏁般�� -8. 閫氱煡鍏憡锛氱郴缁熼�氱煡鍏憡淇℃伅鍙戝竷缁存姢銆� -9. 鎿嶄綔鏃ュ織锛氱郴缁熸甯告搷浣滄棩蹇楄褰曞拰鏌ヨ锛涚郴缁熷紓甯镐俊鎭棩蹇楄褰曞拰鏌ヨ銆� -10. 鐧诲綍鏃ュ織锛氱郴缁熺櫥褰曟棩蹇楄褰曟煡璇㈠寘鍚櫥褰曞紓甯搞�� -11. 鍦ㄧ嚎鐢ㄦ埛锛氬綋鍓嶇郴缁熶腑娲昏穬鐢ㄦ埛鐘舵�佺洃鎺с�� -12. 瀹氭椂浠诲姟锛氬湪绾匡紙娣诲姞銆佷慨鏀广�佸垹闄�)浠诲姟璋冨害鍖呭惈鎵ц缁撴灉鏃ュ織銆� -13. 浠g爜鐢熸垚锛氬墠鍚庣浠g爜鐨勭敓鎴愶紙java銆乭tml銆亁ml銆乻ql锛夋敮鎸丆RUD涓嬭浇 銆� -14. 绯荤粺鎺ュ彛锛氭牴鎹笟鍔′唬鐮佽嚜鍔ㄧ敓鎴愮浉鍏崇殑api鎺ュ彛鏂囨。銆� -15. 鏈嶅姟鐩戞帶锛氱洃瑙嗗綋鍓嶇郴缁烠PU銆佸唴瀛樸�佺鐩樸�佸爢鏍堢瓑鐩稿叧淇℃伅銆� -16. 缂撳瓨鐩戞帶锛氬绯荤粺鐨勭紦瀛樹俊鎭煡璇紝鍛戒护缁熻绛夈�� -17. 鍦ㄧ嚎鏋勫缓鍣細鎷栧姩琛ㄥ崟鍏冪礌鐢熸垚鐩稿簲鐨凥TML浠g爜銆� -18. 杩炴帴姹犵洃瑙嗭細鐩戣褰撳墠绯荤粺鏁版嵁搴撹繛鎺ユ睜鐘舵�侊紝鍙繘琛屽垎鏋怱QL鎵惧嚭绯荤粺鎬ц兘鐡堕銆� - -## 鍦ㄧ嚎浣撻獙 - -- admin/admin123 -- 闄嗛檰缁画鏀跺埌涓�浜涙墦璧忥紝涓轰簡鏇村ソ鐨勪綋楠屽凡鐢ㄤ簬婕旂ず鏈嶅姟鍣ㄥ崌绾с�傝阿璋㈠悇浣嶅皬浼欎即銆� - -婕旂ず鍦板潃锛歨ttp://vue.ruoyi.vip -鏂囨。鍦板潃锛歨ttp://doc.ruoyi.vip - -## 婕旂ず鍥� - -<table> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/cd1f90be5f2684f4560c9519c0f2a232ee8.jpg"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/1cbcf0e6f257c7d3a063c0e3f2ff989e4b3.jpg"/></td> - </tr> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/up-8074972883b5ba0622e13246738ebba237a.png"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/up-9f88719cdfca9af2e58b352a20e23d43b12.png"/></td> - </tr> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/up-39bf2584ec3a529b0d5a3b70d15c9b37646.png"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/up-936ec82d1f4872e1bc980927654b6007307.png"/></td> - </tr> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/up-b2d62ceb95d2dd9b3fbe157bb70d26001e9.png"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/up-d67451d308b7a79ad6819723396f7c3d77a.png"/></td> - </tr> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/5e8c387724954459291aafd5eb52b456f53.jpg"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/644e78da53c2e92a95dfda4f76e6d117c4b.jpg"/></td> - </tr> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/up-8370a0d02977eebf6dbf854c8450293c937.png"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/up-49003ed83f60f633e7153609a53a2b644f7.png"/></td> - </tr> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/up-d4fe726319ece268d4746602c39cffc0621.png"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/up-c195234bbcd30be6927f037a6755e6ab69c.png"/></td> - </tr> - <tr> - <td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td> - <td><img src="https://oscimg.oschina.net/oscnet/up-5e4daac0bb59612c5038448acbcef235e3a.png"/></td> - </tr> -</table> - - -## 鑻ヤ緷鍓嶅悗绔垎绂讳氦娴佺兢 - -QQ缇わ細 [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 鐐瑰嚮鎸夐挳鍏ョ兢銆� \ No newline at end of file diff --git a/basic-server/pom.xml b/basic-server/pom.xml new file mode 100644 index 0000000..b45552d --- /dev/null +++ b/basic-server/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>ruoyi</artifactId> + <groupId>com.ruoyi</groupId> + <version>3.8.9</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>basic-server</artifactId> + <dependencies> + <!-- 閫氱敤宸ュ叿--> + <dependency> + <groupId>com.ruoyi</groupId> + <artifactId>ruoyi-common</artifactId> + </dependency> + + <!-- 鏍稿績妯″潡--> + <dependency> + <groupId>com.ruoyi</groupId> + <artifactId>ruoyi-framework</artifactId> + </dependency> + + <!-- 绯荤粺妯″潡--> + <dependency> + <groupId>com.ruoyi</groupId> + <artifactId>ruoyi-system</artifactId> + </dependency> + </dependencies> + + <properties> + <maven.compiler.source>8</maven.compiler.source> + <maven.compiler.target>8</maven.compiler.target> + </properties> + +</project> diff --git a/bin/clean.bat b/bin/clean.bat deleted file mode 100644 index 24c0974..0000000 --- a/bin/clean.bat +++ /dev/null @@ -1,12 +0,0 @@ -@echo off -echo. -echo [信息] 清理工程target生成路径。 -echo. - -%~d0 -cd %~dp0 - -cd .. -call mvn clean - -pause \ No newline at end of file diff --git a/bin/package.bat b/bin/package.bat deleted file mode 100644 index c693ec0..0000000 --- a/bin/package.bat +++ /dev/null @@ -1,12 +0,0 @@ -@echo off -echo. -echo [信息] 打包Web工程,生成war/jar包文件。 -echo. - -%~d0 -cd %~dp0 - -cd .. -call mvn clean package -Dmaven.test.skip=true - -pause \ No newline at end of file diff --git a/bin/run.bat b/bin/run.bat deleted file mode 100644 index 41efbd0..0000000 --- a/bin/run.bat +++ /dev/null @@ -1,14 +0,0 @@ -@echo off -echo. -echo [信息] 使用Jar命令运行Web工程。 -echo. - -cd %~dp0 -cd ../ruoyi-admin/target - -set JAVA_OPTS=-Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m - -java -jar %JAVA_OPTS% ruoyi-admin.jar - -cd bin -pause \ No newline at end of file diff --git a/pom.xml b/pom.xml index 80cc54d..c91e139 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,8 @@ <jakarta.version>6.0.0</jakarta.version> <springdoc.version>2.6.0</springdoc.version> <postgresql.version>42.7.3</postgresql.version> + <mybatis-plus.version>3.5.3.1</mybatis-plus.version> + <freemarker.version>2.3.30</freemarker.version> </properties> <!-- 渚濊禆澹版槑 --> @@ -70,13 +72,7 @@ <artifactId>pagehelper-spring-boot-starter</artifactId> <version>${pagehelper.boot.version}</version> </dependency> - - <dependency> - <groupId>org.mybatis.spring.boot</groupId> - <artifactId>mybatis-spring-boot-starter</artifactId> - <version>${mybatis-spring-boot.version}</version> - </dependency> - + <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> @@ -192,8 +188,44 @@ <version>${postgresql.version}</version> </dependency> + <!--鍩虹妯″潡--> + <dependency> + <groupId>com.ruoyi</groupId> + <artifactId>basic-server</artifactId> + <version>${ruoyi.version}</version> + </dependency> </dependencies> </dependencyManagement> + + <!-- 鍏ㄥ眬寮曞叆 --> + <dependencies> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <scope>provided</scope> + </dependency> + + <!--mybatis-plus--> + <dependency> + <groupId>com.baomidou</groupId> + <artifactId>mybatis-plus-boot-starter</artifactId> + <version>${mybatis-plus.version}</version> + </dependency> + + <!--mybatis-plus浠g爜鐢熸垚鍣�--> + <dependency> + <groupId>com.baomidou</groupId> + <artifactId>mybatis-plus-generator</artifactId> + <version>${mybatis-plus.version}</version> + </dependency> + + <dependency> + <groupId>org.freemarker</groupId> + <artifactId>freemarker</artifactId> + <version>${freemarker.version}</version> + </dependency> + + </dependencies> <modules> <module>ruoyi-admin</module> @@ -202,6 +234,7 @@ <module>ruoyi-quartz</module> <module>ruoyi-generator</module> <module>ruoyi-common</module> + <module>basic-server</module> </modules> <packaging>pom</packaging> diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 33d0aba..0e5b56c 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -86,6 +86,18 @@ <artifactId>postgresql</artifactId> </dependency> + <!-- FreeMarker 妯℃澘寮曟搸 --> + <dependency> + <groupId>org.freemarker</groupId> + <artifactId>freemarker</artifactId> + <version>2.3.31</version> <!-- 鍙牴鎹渶瑕佽皟鏁寸増鏈� --> + </dependency> + + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity-engine-core</artifactId> + <version>2.3</version> + </dependency> </dependencies> diff --git a/ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java b/ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java new file mode 100644 index 0000000..196735f --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java @@ -0,0 +1,162 @@ +package com.ruoyi; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.generator.FastAutoGenerator; +import com.baomidou.mybatisplus.generator.config.OutputFile; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; +import com.baomidou.mybatisplus.generator.fill.Column; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * MyBatis-Plus 浠g爜鐢熸垚鍣� + * 鍔熻兘锛氭牴鎹暟鎹簱琛ㄧ粨鏋勮嚜鍔ㄧ敓鎴怑ntity銆丮apper銆丼ervice銆丆ontroller绛変唬鐮� + * 淇锛氳В鍐矲reemarker妯℃澘涓璯enerateService鍙橀噺缂哄け鐨勯棶棰� + */ +@SpringBootApplication +public class PlusCodeGenerator { + + // 鏁版嵁搴撻厤缃� + private static final String DB_URL = "jdbc:postgresql://lunor.cn:5431/ruoyi-java"; + private static final String DB_USERNAME = "test"; + private static final String DB_PASSWORD = "chj123456"; + + // 椤圭洰鍩虹閰嶇疆 + private static final String BASE_PACKAGE = "com.ruoyi"; + private static final String MODULE_NAME = "basic"; // 妯″潡鍚� + + public static void main(String[] args) { + String projectPath = System.getProperty("user.dir"); // 鑾峰彇椤圭洰鏍硅矾寰� + String path = "basic-server"; // 妯″潡鍚嶇О + String table = "test"; // 琛ㄥ悕锛屽涓〃閫楀彿闅斿紑 + + // 浠g爜杈撳嚭璺緞閰嶇疆 + String outputBasePath = Paths.get(projectPath, path, "src", "main", "java").toString(); + String outputResourcePath = Paths.get(projectPath, path, "src", "main", "resources", "mapper").toString(); + + // 浠g爜鐢熸垚鏍稿績閰嶇疆 + FastAutoGenerator.create(DB_URL, DB_USERNAME, DB_PASSWORD) + .globalConfig(builder -> { + builder.author("ruoyi") // 浣滆�呬俊鎭� + .outputDir(outputBasePath) // 浠g爜杈撳嚭鐩綍 + .dateType(DateType.ONLY_DATE) // 鏃ユ湡绫诲瀷 + .commentDate("yyyy-MM-dd") // 娉ㄩ噴鏃ユ湡鏍煎紡 + .disableOpenDir(); // 绂佹鑷姩鎵撳紑杈撳嚭鐩綍 + }) + .packageConfig(builder -> { + builder.parent(BASE_PACKAGE) // 鍩虹鍖呭悕 + .moduleName(MODULE_NAME) // 妯″潡鍚� + .entity("entity") // Entity鍖呭悕 + .mapper("mapper") // Mapper鍖呭悕 + .service("service") // Service鍖呭悕 + .serviceImpl("service.impl") // Service瀹炵幇绫诲寘鍚� + .controller("controller") // Controller鍖呭悕 + .pathInfo(Collections.singletonMap( + OutputFile.xml, + outputResourcePath // Mapper XML杈撳嚭璺緞 + )); + }) + .strategyConfig(builder -> { + builder.addInclude(table) // 瑕佺敓鎴愮殑琛ㄥ悕 + .addTablePrefix("t_", "sys_") // 杩囨护琛ㄥ墠缂� + + // 瀹炰綋绫婚厤缃� + .entityBuilder() + .superClass("com.ruoyi.common.core.domain.BaseEntity") // 缁ф壙鍩虹被 + .addSuperEntityColumns("create_by", "create_time", "update_by", "update_time") // 鎺掗櫎鍩虹被瀛楁 + .enableLombok() // 鍚敤Lombok + .naming(NamingStrategy.underline_to_camel) // 琛ㄥ悕杞┘宄� + .columnNaming(NamingStrategy.underline_to_camel) // 鍒楀悕杞┘宄� + .enableFileOverride() // 鍏佽瑕嗙洊鏂囦欢 + .logicDeleteColumnName("deleted") // 閫昏緫鍒犻櫎瀛楁 + .addTableFills( + // 鑷姩濉厖閰嶇疆 + new Column("create_by", FieldFill.INSERT), // 鍒涘缓浜猴紝鎻掑叆鏃跺~鍏� + new Column("update_by", FieldFill.INSERT_UPDATE), // 鏇存柊浜猴紝鎻掑叆鍜屾洿鏂版椂濉厖 + new Column("create_time", FieldFill.INSERT), // 鍒涘缓鏃堕棿锛屾彃鍏ユ椂濉厖 + new Column("update_time", FieldFill.INSERT_UPDATE) // 鏇存柊鏃堕棿锛屾彃鍏ュ拰鏇存柊鏃跺~鍏� + ) + .idType(IdType.AUTO) // 涓婚敭绛栫暐 + .enableTableFieldAnnotation() // 鍚敤瀛楁娉ㄨВ + + // 鎺у埗鍣ㄩ厤缃� + .controllerBuilder() + .enableFileOverride() // 鍏佽瑕嗙洊 + .enableRestStyle() // 鐢熸垚RESTful椋庢牸鎺у埗鍣� + + // Service閰嶇疆 + .serviceBuilder() + .formatServiceFileName("%sService") // Service鎺ュ彛鍛藉悕鏍煎紡 + .enableFileOverride() // 鍏佽瑕嗙洊 + .formatServiceImplFileName("%sServiceImpl") // Service瀹炵幇绫诲懡鍚嶆牸寮� + .enableFileOverride() // 鍏佽瑕嗙洊 + + // Mapper閰嶇疆 + .mapperBuilder() + .enableFileOverride() // 鍏佽瑕嗙洊 + .enableMapperAnnotation() // 鍚敤@Mapper娉ㄨВ + .enableBaseResultMap() // 鍚敤鍩虹ResultMap + .enableBaseColumnList() // 鍚敤鍩虹ColumnList + .formatMapperFileName("%sMapper") // Mapper鎺ュ彛鍛藉悕鏍煎紡 + .formatXmlFileName("%sMapper") // Mapper XML鍛藉悕鏍煎紡 + .enableFileOverride(); // 鍏佽瑕嗙洊 + }) + // 閰嶇疆鑷畾涔夋ā鏉� + .templateConfig(builder -> { + builder + .entity("/templates/entity.java") // 瀹炰綋绫绘ā鏉� + .xml("/templates/mapper.xml") // Mapper XML妯℃澘 + .controller("/templates/controller.java") // 鎺у埗鍣ㄦā鏉� + .serviceImpl("/templates/serviceImpl.java"); // Service瀹炵幇绫绘ā鏉� + }) + // 娉ㄥ叆妯℃澘鍙橀噺 + .injectionConfig(builder -> { + Map<String, Object> customMap = new HashMap<>(); + customMap.put("superEntityColumns", Arrays.asList( + "create_by", "create_time", "update_by", "update_time" + )); // 鍩虹被瀛楁 + customMap.put("idType", "AUTO"); // 涓婚敭绫诲瀷 + customMap.put("superEntityClass", "com.ruoyi.common.core.domain.BaseEntity"); // 鍩虹被鍏ㄨ矾寰� + customMap.put("author", "ruoyi"); // 浣滆�呬俊鎭� + customMap.put("packageName", BASE_PACKAGE + "." + MODULE_NAME); // 鍖呭悕 + customMap.put("tableName", table); // 琛ㄥ悕 + + // 鏂板锛氳В鍐矲reemarker妯℃澘涓璯enerateService鍙橀噺缂哄け鐨勯棶棰� + // 鎺у埗Service瀹炵幇绫绘槸鍚﹀疄鐜癝ervice鎺ュ彛 + boolean generateService = true; + customMap.put("generateService", generateService); + + builder.customMap(customMap); + }) + .templateEngine(new FreemarkerTemplateEngine()) // 浣跨敤Freemarker妯℃澘寮曟搸 + .execute(); // 鎵ц浠g爜鐢熸垚 + + // 鍚庡鐞嗭細淇瀹炰綋绫荤殑瀹屽叏闄愬畾鍚嶉棶棰� + try { + Path entityPath = Paths.get(outputBasePath, "com/ruoyi/basic/entity/Test.java"); + if (Files.exists(entityPath)) { + String content = Files.readString(entityPath); + content = content.replace( + "extends com.ruoyi.common.core.domain.BaseEntity", + "extends BaseEntity" + ); // 绠�鍖栧熀绫诲紩鐢� + Files.writeString(entityPath, content); + } + } catch (IOException e) { + System.err.println("鈿狅笍 淇瀹炰綋绫诲け璐�: " + e.getMessage()); + } + + System.out.println("鉁� 浠g爜鐢熸垚瀹屾垚锛佹枃浠跺凡杈撳嚭鍒帮細" + outputBasePath); + } +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/controller.Java.ftl b/ruoyi-admin/src/main/resources/templates/controller.Java.ftl new file mode 100644 index 0000000..3e51536 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/controller.Java.ftl @@ -0,0 +1,40 @@ +package ${package.Controller}; + +import org.springframework.web.bind.annotation.RequestMapping; +import lombok.AllArgsConstructor; +<#if restControllerStyle> + import org.springframework.web.bind.annotation.RestController; +<#else> + import org.springframework.stereotype.Controller; +</#if> +<#if superControllerClassPackage??> + import ${superControllerClassPackage}; +</#if> + +/** +* <p> + * ${table.comment!} 鍓嶇鎺у埗鍣� + * </p> +* +* @author ${author} +* @since ${date} +*/ + +<#if restControllerStyle> +@RestController +<#else> +@Controller +</#if> +@AllArgsConstructor +@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>") +<#if kotlin> + class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if> +<#else> + <#if superControllerClass??> + public class ${table.controllerName} extends ${superControllerClass} { + <#else> + public class ${table.controllerName} { + </#if> + + } +</#if> \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/entity.java.ftl b/ruoyi-admin/src/main/resources/templates/entity.java.ftl new file mode 100644 index 0000000..70f2673 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/entity.java.ftl @@ -0,0 +1,44 @@ +package ${package.Entity}; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +<#if superEntityClass?? && superEntityClass != ""> + import ${superEntityClass}; +</#if> +<#list table.fields as field> + <#if field.propertyType == "LocalDateTime"> + import java.time.LocalDateTime; + <#break> + </#if> +</#list> + +/** +* ${table.comment!} 瀹炰綋绫� +* +* @author ${author!"admin"} +* @date ${.now?string("yyyy-MM-dd")} +*/ +@Data +@TableName("${table.name}") +public class ${entity} <#if superEntityClass?? && superEntityClass != "">extends ${superEntityClass?substring(superEntityClass?last_index_of(".") + 1)}</#if> { + +private static final long serialVersionUID = 1L; + +<#list table.fields as field> +<#-- 淇锛氭坊鍔� superEntityColumns 瀛樺湪鎬ф鏌� --> + <#if superEntityColumns?? && !superEntityColumns?seq_contains(field.name)> + /** + * ${field.comment!} + */ + <#if field.keyFlag> + @TableId(value = "${field.name}", type = IdType.${idType!"AUTO"}) + <#else> + @TableField(value = "${field.name}"<#if field.fill?? && field.fill != "">, fill = FieldFill.${field.fill?upper_case}</#if>) + </#if> + <#if field.logicDeleteField> + @TableLogic + </#if> + private ${field.propertyType} ${field.propertyName}; + </#if> +</#list> +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/mapper.xml.ftl b/ruoyi-admin/src/main/resources/templates/mapper.xml.ftl new file mode 100644 index 0000000..9dc8071 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/mapper.xml.ftl @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="${package.Mapper}.${table.mapperName}"> + + <#if enableCache> + <!-- 寮�鍚簩绾х紦瀛� --> + <cache type="${cacheClassName}"/> + + </#if> + <#if baseResultMap> + <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 --> + <resultMap id="BaseResultMap" type="${package.Entity}.${entity}"> + <#list table.fields as field> + <#if field.keyFlag><#--鐢熸垚涓婚敭鎺掑湪绗竴浣�--> + <id column="${field.name}" property="${field.propertyName}" /> + </#if> + </#list> + <#list table.commonFields as field><#--鐢熸垚鍏叡瀛楁 --> + <result column="${field.name}" property="${field.propertyName}" /> + </#list> + <#list table.fields as field> + <#if !field.keyFlag><#--鐢熸垚鏅�氬瓧娈� --> + <result column="${field.name}" property="${field.propertyName}" /> + </#if> + </#list> + </resultMap> + + </#if> + <#if baseColumnList> + <!-- 閫氱敤鏌ヨ缁撴灉鍒� --> + <sql id="Base_Column_List"> + <#list table.commonFields as field> + ${field.columnName}, + </#list> + ${table.fieldNames} + </sql> + + </#if> +</mapper> \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/serviceImpl.java.ftl b/ruoyi-admin/src/main/resources/templates/serviceImpl.java.ftl new file mode 100644 index 0000000..df75063 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/serviceImpl.java.ftl @@ -0,0 +1,30 @@ +package ${package.ServiceImpl}; + +import ${package.Entity}.${entity}; +import ${package.Mapper}.${table.mapperName}; +<#if generateService> + import ${package.Service}.${table.serviceName}; +</#if> +import ${superServiceImplClassPackage}; +import org.springframework.stereotype.Service; +import lombok.RequiredArgsConstructor; + +/** +* <p> + * ${table.comment!} 鏈嶅姟瀹炵幇绫� + * </p> +* +* @author ${author} +* @since ${date} +*/ +@Service +@RequiredArgsConstructor +<#if kotlin> + open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>()<#if generateService>, ${table.serviceName}</#if> { + + } +<#else> + public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}><#if generateService> implements ${table.serviceName}</#if> { + + } +</#if> \ No newline at end of file diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/PlusCodeGenerator.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/PlusCodeGenerator.java deleted file mode 100644 index 313e9bc..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/PlusCodeGenerator.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.ruoyi.generator; - -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.generator.FastAutoGenerator; -import com.baomidou.mybatisplus.generator.config.OutputFile; -import com.baomidou.mybatisplus.generator.config.rules.DateType; -import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; -import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; -import com.baomidou.mybatisplus.generator.fill.Column; - -import java.util.Collections; - -/** - * MyBatis-Plus 浠g爜鐢熸垚鍣� - */ -public class PlusCodeGenerator { - - public static void main(String[] args) { - // 鏁版嵁搴撻厤缃� - String url = "jdbc:postgresql://lunor.cn:5431/ruoyi-java"; - String username = "test"; - String password = "chj123456"; - - // 椤圭洰鍩虹鍖呭悕 - String basePackage = "com.example"; - - String projectPath = System.getProperty("user.dir"); - - FastAutoGenerator.create(url, username, password) - .globalConfig(builder -> { - builder.author("your name") // 璁剧疆浣滆�� - .outputDir(System.getProperty("user.dir") + "/src/main/java") // 鎸囧畾杈撳嚭鐩綍 - .dateType(DateType.ONLY_DATE) // 璁剧疆鏃堕棿绫诲瀷绛栫暐 - .disableOpenDir(); // 绂佹鎵撳紑杈撳嚭鐩綍 - }) - .packageConfig(builder -> { - builder.parent(basePackage) // 璁剧疆鐖跺寘鍚� - .moduleName("test") // 璁剧疆鐖跺寘妯″潡鍚� - .entity("entity") // 璁剧疆瀹炰綋绫诲寘鍚� - .mapper("mapper") // 璁剧疆 Mapper 鎺ュ彛鍖呭悕 - .service("service") // 璁剧疆 Service 鎺ュ彛鍖呭悕 - .serviceImpl("service.impl") // 璁剧疆 Service 瀹炵幇绫诲寘鍚� - .pathInfo(Collections.singletonMap(OutputFile.xml, projectPath + "/src/main/resources/mapper")); // 璁剧疆mapperXml鐢熸垚璺緞 - }) - .strategyConfig(builder -> { - builder.addInclude("test") // 璁剧疆闇�瑕佺敓鎴愮殑琛ㄥ悕 - .addTablePrefix("t_", "sys_") // 璁剧疆杩囨护琛ㄥ墠缂� - // Entity 绛栫暐閰嶇疆 - .entityBuilder() - .enableLombok() //寮�鍚� Lombok - .naming(NamingStrategy.underline_to_camel) //鏁版嵁搴撹〃鏄犲皠鍒板疄浣撶殑鍛藉悕绛栫暐锛氫笅鍒掔嚎杞┘宄板懡 - .columnNaming(NamingStrategy.underline_to_camel) //鏁版嵁搴撹〃瀛楁鏄犲皠鍒板疄浣撶殑鍛藉悕绛栫暐锛氫笅鍒掔嚎杞┘宄板懡 - .enableFileOverride() // 瑕嗙洊宸茬粡鐢熸垚鐨凟ntity鏂囦欢 - .logicDeleteColumnName("deleted") // 璁剧疆閫昏緫鍒犻櫎瀛楁 - .addTableFills( - new Column("deleted", FieldFill.INSERT), - new Column("create_time", FieldFill.INSERT), - new Column("update_time", FieldFill.INSERT_UPDATE), - new Column("create_user", FieldFill.INSERT), - new Column("update_user", FieldFill.INSERT_UPDATE) - ) - .idType(IdType.AUTO) // 鑷涓婚敭 - .enableTableFieldAnnotation() // 寮�鍚敓鎴愬疄浣撴椂鐢熸垚瀛楁娉ㄨВ - // Mapper 绛栫暐閰嶇疆 - .mapperBuilder() - .enableFileOverride() // 瑕嗙洊宸茬敓鎴怣apper鏂囦欢 - .enableBaseResultMap() // 鑷姩鐢熸垚resultMap - .enableBaseColumnList() // 鍚敤 BaseColumnList - // Service 绛栫暐閰嶇疆 - .serviceBuilder() - .formatServiceFileName("%sService") - .formatServiceImplFileName("%sServiceImpl") - .enableFileOverride() // 瑕嗙洊宸茬敓鎴愭枃浠� - // Controller 绛栫暐閰嶇疆 - .controllerBuilder() - .enableRestStyle() // 寮�鍚疪estController娉ㄨВ - .enableFileOverride() // 瑕嗙洊宸茬敓鎴愭枃浠� - ; - }) - .templateEngine(new FreemarkerTemplateEngine()) // 浣跨敤Freemarker寮曟搸妯℃澘锛岄粯璁ょ殑鏄疺elocity寮曟搸 - .execute(); - } -} \ No newline at end of file diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java index c01857c..536d13f 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java @@ -35,6 +35,8 @@ return author; } + private final boolean useMyBatisPlus = false; // 鏄惁浣跨敤 MyBatis-Plus + @Value("${author}") public void setAuthor(String author) { @@ -84,4 +86,8 @@ { GenConfig.allowOverwrite = allowOverwrite; } + + public boolean isUseMyBatisPlus() { + return useMyBatisPlus; + } } -- Gitblit v1.9.3