摘要:代碼生成代碼生成內(nèi)容在基礎(chǔ)上,新增等模板拓展,生成通用分頁方法代碼生成模板數(shù)據(jù)庫新建表,即可生成后臺(tái)分頁基礎(chǔ)代碼,還有官網(wǎng)地址代碼生成步驟創(chuàng)建數(shù)據(jù)庫表,例如注意記得加上表注釋,字段列注釋,方便生成類注釋注釋
spring-boot-plus 代碼生成 Generator 代碼生成內(nèi)容
spring-boot-plus在mybatis-plus基礎(chǔ)上,新增param/vo等模板
拓展controller/service/mapper/xml,生成通用CRUD/分頁方法
代碼生成模板:spring-boot-plus/src/test/resources/templates
Purpose數(shù)據(jù)庫新建表,即可生成后臺(tái)CRUD/分頁基礎(chǔ)代碼,還有swagger!
_ _ _ _ (_) | | | | | | ___ _ __ _ __ _ _ __ __ _ ______| |__ ___ ___ | |_ ______ _ __ | |_ _ ___ / __| "_ | "__| | "_ / _` |______| "_ / _ / _ | __|______| "_ | | | | / __| \__ |_) | | | | | | | (_| | | |_) | (_) | (_) | |_ | |_) | | |_| \__ |___/ .__/|_| |_|_| |_|\__, | |_.__/ \___/ \___/ \__| | .__/|_|\__,_|___/ | | __/ | | | |_| |___/ |_| :: Spring Boot :: (v2.1.6.RELEASE) :: Spring Boot Plus :: (v1.0.0.RELEASE)代碼生成步驟
創(chuàng)建數(shù)據(jù)庫表,例如:sys_log
注意:記得加上表注釋,字段列注釋,方便生成類注釋、swagger注釋
-- ---------------------------- -- Table structure for sys_log -- ---------------------------- DROP TABLE IF EXISTS `sys_log`; CREATE TABLE `sys_log` ( `log_id` bigint(18) NOT NULL COMMENT "主鍵", `type` tinyint(1) NULL DEFAULT NULL COMMENT "類型", `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "內(nèi)容", `create_id` bigint(18) NULL DEFAULT NULL COMMENT "創(chuàng)建人ID", `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT "創(chuàng)建時(shí)間", PRIMARY KEY (`log_id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "系統(tǒng)日志" ROW_FORMAT = Dynamic;
代碼生成配置
spring-boot-plus/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java
2.1 修改數(shù)據(jù)庫連接配置
private static final String USER_NAME = "root"; private static final String PASSWORD = "rootroot"; private static final String DRIVER_NAME = "com.mysql.jdbc.Driver"; private static final String DRIVER_URL = "jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
2.2 修改模塊、表、作者等配置
// ############################ 配置部分 start ############################ // 模塊名稱 private static final String MODULE_NAME = "system"; // 作者 private static final String AUTHOR = "geekidea"; // 生成的表名稱 private static final String TABLE_NAME = "sys_log"; // 主鍵數(shù)據(jù)庫列名稱 private static final String PK_ID_COLUMN_NAME = "log_id"; // 代碼生成策略 true:All/false:SIMPLE private static final boolean GENERATOR_STRATEGY = true; // 分頁列表查詢是否排序 true:有排序參數(shù)/false:無 private static final boolean PAGE_LIST_ORDER = true; // ############################ 配置部分 end ############################
MODULE_NAME:模塊名稱,在目前項(xiàng)目上以多帶帶的文件夾形式體現(xiàn)
AUTHOR:作者名稱,在類的注釋上體現(xiàn)
TABLE_NAME:表名稱,當(dāng)前需要生成的表名稱,關(guān)聯(lián)實(shí)體類等
PK_ID_COLUMN_NAME:主鍵列名稱,默認(rèn)是id,如果是其它名稱,可在這里配置
GENERATOR_STRATEGY:代碼生成策略 true:All/false:SIMPLE
PAGE_LIST_ORDER:分頁列表查詢是否排序 true:有排序參數(shù)/false:無
運(yùn)行CodeGenerator.java
3.1 控制臺(tái)輸出生成日志
11:33:43.442 [main] DEBUG com.baomidou.mybatisplus.generator.AutoGenerator - ==========================準(zhǔn)備生成文件...========================== 11:33:44.167 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 創(chuàng)建目錄: [E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystementity] 11:33:44.169 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 創(chuàng)建目錄: [E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemwebcontroller] 11:33:44.170 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 創(chuàng)建目錄: [E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemservice] 11:33:44.170 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 創(chuàng)建目錄: [E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemmapper] 11:33:44.171 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 創(chuàng)建目錄: [E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemserviceimpl] ... 11:33:44.294 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/mapper.xml.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.308 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/mapper.xml.vm; 文件:E:githubspring-boot-plus/src/main/resources/mapper/system/SysLogMapper.xml 11:33:44.313 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/queryParam.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.314 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/queryParam.java.vm; 文件:E:githubspring-boot-plus/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java 11:33:44.332 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/queryVo.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.337 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/queryVo.java.vm; 文件:E:githubspring-boot-plus/src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java 11:33:44.347 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/entity.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.357 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/entity.java.vm; 文件:E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystementitySysLog.java 11:33:44.359 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/mapper.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.360 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/mapper.java.vm; 文件:E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemmapperSysLogMapper.java 11:33:44.362 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/service.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.364 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/service.java.vm; 文件:E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemserviceSysLogService.java 11:33:44.367 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/serviceImpl.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.369 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/serviceImpl.java.vm; 文件:E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemserviceimplSysLogServiceImpl.java 11:33:44.373 [main] DEBUG org.apache.velocity - ResourceManager : found /templates/controller.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 11:33:44.376 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/controller.java.vm; 文件:E:githubspring-boot-plus/src/main/javaiogeekideaspringbootplussystemwebcontrollerSysLogController.java 11:33:44.376 [main] DEBUG com.baomidou.mybatisplus.generator.AutoGenerator - ==========================文件生成完成!!!========================== Process finished with exit code 0
3.2 生成的模塊和包結(jié)構(gòu)
├─system 模塊包 │ ├─entity 實(shí)體類包 │ ├─mapper mybatis mapper接口包 │ ├─service 服務(wù)接口包 │ │ └─impl 服務(wù)實(shí)現(xiàn)包 │ └─web 提供前端結(jié)果相關(guān)包 │ ├─controller 控制器包 │ ├─param 參數(shù)包 │ └─vo 值對(duì)象,響應(yīng)結(jié)果包
3.3 生成的包及相關(guān)的類
├─system │ ├─entity │ │ SysLog.java 實(shí)體類,已生成swagger注釋 │ ├─mapper │ │ SysLogMapper.java mapper接口 │ ├─service │ │ │ SysLogService.java 服務(wù)接口,已繼承公共service │ │ └─impl │ │ SysLogServiceImpl.java 服務(wù)實(shí)現(xiàn)類,已繼承公共service impl │ └─web │ ├─controller │ │ SysLogController.java 控制器類,已生成CRUD,分頁controller方法,已生成swagger文檔 │ ├─param │ │ SysLogQueryParam.java 請(qǐng)求參數(shù)類,用于條件分頁查詢等 │ └─vo │ SysLogQueryVo.java 響應(yīng)結(jié)果類,用于自定義查詢響應(yīng)結(jié)果等啟動(dòng)項(xiàng)目
SpringBootPlusApplication.java
2019-07-27 12:11:45.298 INFO 21856 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8888 (http) with context path "" 2019-07-27 12:11:45.301 INFO 21856 --- [ main] i.g.s.SpringBootPlusApplication : Started SpringBootPlusApplication in 9.66 seconds (JVM running for 10.988) 2019-07-27 12:11:45.304 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : projectFinalName : spring-boot-plus 2019-07-27 12:11:45.305 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : projectVersion : 1.0.0.RELEASE 2019-07-27 12:11:45.305 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : profileActive : local 2019-07-27 12:11:45.305 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : contextPath : / 2019-07-27 12:11:45.305 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : port : 8888 2019-07-27 12:11:45.308 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : home:http://192.168.1.168:8888/ 2019-07-27 12:11:45.308 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : docs:http://192.168.1.168:8888/docs 2019-07-27 12:11:45.308 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : spring-boot-plus project start success........... 2019-07-27 12:11:45.309 INFO 21856 --- [ main] i.g.s.util.PrintApplicationInfo : ____ __ __ ____ / _` / \__ / \__ / _` ,L\_ ,_ __ _ __ ,_ ,L\_ __ __ ___ ___ __ ____ ____ /_\__ / /"__` /`"__ / /_\__ / / /"___ /"___ /"__` /",__ /",__ / L \_/ L.\_ / \_ / L \_ / \__// \__// __//\__, `/\__, ` `\____ \__ \__/.\_ \_ \__ `\____ \____/ \____ \____ \____/\____//\____/ /_____//__//__//_/ /_/ /__/ /_____//___/ /____//____//____//___/ /___/訪問項(xiàng)目
http://localhost:8888/swagger-ui.html或者訪問本地ip
http://192.168.xxx.xxx:8888/swagger-ui.html
自動(dòng)生成swagger CRUD、分頁接口文檔
add 添加接口swagger
delete 刪除接口swagger
getPageList 分頁接口swagger
info 詳情接口swagger
update 修改接口swagger
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/76095.html
摘要:代碼生成在基礎(chǔ)上,新增等模板拓展,生成通用分頁方法代碼生成模板數(shù)據(jù)庫新建表,即可生成后臺(tái)分頁基礎(chǔ)代碼,還有官網(wǎng)地址代碼生成步驟創(chuàng)建數(shù)據(jù)庫表,例如注意記得加上表注釋,字段列注釋,方便生成類注釋注釋 代碼生成 Generator spring-boot-plus在mybatis-plus基礎(chǔ)上,新增param/vo等模板拓展controller/service/mapper/xml,生成通...
摘要:是一套集成常用開發(fā)組件的后臺(tái)快速開發(fā)框架每個(gè)人都可以獨(dú)立快速高效地開發(fā)項(xiàng)目官網(wǎng)地址主要特性集成常用開發(fā)組件集公共配置日志等集成快速操作快速生成后臺(tái)代碼集成,可自動(dòng)生成文檔集成權(quán)限控制集成緩存集成消息隊(duì)列集成連接池,性能和慢查詢檢 Introduction spring-boot-plus是一套集成spring boot常用開發(fā)組件的后臺(tái)快速開發(fā)框架 Purpose 每個(gè)人都可以獨(dú)立、快...
閱讀 2853·2021-09-10 10:51
閱讀 2220·2021-09-02 15:21
閱讀 3214·2019-08-30 15:44
閱讀 880·2019-08-29 18:34
閱讀 1659·2019-08-29 13:15
閱讀 3329·2019-08-26 11:37
閱讀 2702·2019-08-26 10:46
閱讀 1115·2019-08-26 10:26