spring-boot-plus Background Quick Development Scaffold Code Generator

Posted by scliburn on Sat, 27 Jul 2019 08:29:26 +0200

Generator code generation

Code generation content

spring-boot-plus adds param/vo and other templates on the basis of mybatis-plus
Extending controller/service/mapper/xml method

Purpose

New tables in the database can generate background CRUD / paging base code, and swagger!

Official address: springboot.plus
GITHUB: https://github.com/geekidea/spring-boot-plus
GITEE: https://gitee.com/geekidea/spring-boot-plus
                 _                    _                 _                _
                (_)                  | |               | |              | |
  ___ _ __  _ __ _ _ __   __ _ ______| |__   ___   ___ | |_ ______ _ __ | |_   _ ___
 / __| '_ \| '__| | '_ \ / _` |______| '_ \ / _ \ / _ \| __|______| '_ \| | | | / __|
 \__ \ |_) | |  | | | | | (_| |      | |_) | (_) | (_) | |_       | |_) | | |_| \__ \
 |___/ .__/|_|  |_|_| |_|\__, |      |_.__/ \___/ \___/ \__|      | .__/|_|\__,_|___/
     | |                  __/ |                                   | |
     |_|                 |___/                                    |_|

      :: Spring Boot ::             (v2.1.6.RELEASE)
      :: Spring Boot Plus ::        (v1.0.0.RELEASE)

Code generation steps

  1. Create database tables, such as sys_log

Note: Remember to add table annotations, field column annotations to facilitate the generation of class annotations, swagger annotations

-- ----------------------------
-- Table structure for sys_log
-- ----------------------------
DROP TABLE IF EXISTS `sys_log`;
CREATE TABLE `sys_log`  (
  `log_id` bigint(18) NOT NULL COMMENT 'Primary key',
  `type` tinyint(1) NULL DEFAULT NULL COMMENT 'type',
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'content',
  `create_id` bigint(18) NULL DEFAULT NULL COMMENT 'Founder ID',
  `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
  PRIMARY KEY (`log_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'system log' ROW_FORMAT = Dynamic;
  1. Code generation configuration
spring-boot-plus/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java

[External Link Picture Transfer Failure (img-fqHAf1sv-1564208072596) https://raw.githubusercontent.com/geekidea/spring-boot-plus-doc/master/.vuepress/public/img/generator-config-location.png)]

2.1 Modify database connection configuration

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 Modify the configuration of modules, tables, authors, etc.

// ############################ Configuration section start############################
// Module name
private static final String MODULE_NAME = "system";
// author
private static final String AUTHOR = "geekidea";
// Generated table name
private static final String TABLE_NAME = "sys_log";
// Primary key database column name
private static final String PK_ID_COLUMN_NAME = "id";
// ############################ Configuration section end############################
  • The name of the MODULE_NAME module is represented as a separate folder on the current project
  • AUTHOR author name, reflected in class annotations
  • TABLE_NAME table name, table name currently needed to be generated, associated entity class, etc.
  • PK_ID_COLUMN_NAME primary key column name, default is id, if other name, can be configured here
  1. Run CodeGenerator.java

3.1 Console Output Generation Log

11:33:43.442 [main] DEBUG com.baomidou.mybatisplus.generator.AutoGenerator - ==========================Prepare to generate files...==========================
11:33:44.167 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - Create a directory: [E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\entity]
11:33:44.169 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - Create a directory: [E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\web\controller]
11:33:44.170 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - Create a directory: [E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\service]
11:33:44.170 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - Create a directory: [E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\mapper]
11:33:44.171 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - Create a directory: [E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\service\impl]
...
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 - Template:/templates/mapper.xml.vm;  file:E:\github\spring-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 - Template:/templates/queryParam.java.vm;  file:E:\github\spring-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 - Template:/templates/queryVo.java.vm;  file:E:\github\spring-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 - Template:/templates/entity.java.vm;  file:E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\entity\SysLog.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 - Template:/templates/mapper.java.vm;  file:E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\mapper\SysLogMapper.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 - Template:/templates/service.java.vm;  file:E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\service\SysLogService.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 - Template:/templates/serviceImpl.java.vm;  file:E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\service\impl\SysLogServiceImpl.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 - Template:/templates/controller.java.vm;  file:E:\github\spring-boot-plus/src/main/java\io\geekidea\springbootplus\system\web\controller\SysLogController.java
11:33:44.376 [main] DEBUG com.baomidou.mybatisplus.generator.AutoGenerator - ==========================File generation completed!!!==========================

Process finished with exit code 0

3.2 Generated Module and Package Structure

-system module package
 -entity Entity Class Package
 -mapper mybatis mapper interface package
 -service service service interface package
 -impl Service Implementation Package
 web provides front-end results related packages
 -controller Controller Package
 -param parameter package
 Response result package for -vo value object

3.3 Generated packages and related classes

├─system                                
│  ├─entity                             
SysLog.java entity class, generated swagger annotations
│  ├─mapper                             
SysLogMapper. Java mapper interface
│  ├─service                            
SysLogService.java service interface, inherited from public service
│  │  └─impl                            
SysLogServiceImpl.java service implementation class, inherited from public service impl
│  └─web                                
│      ├─controller                     
SysLogController.java controller class, generated CRUD, paging controller method, generated swagger document
│      ├─param                                                
SysLogQueryParam.java request parameter class for conditional paging queries, etc.
│      └─vo                             
SysLogQueryVo.java response result class for customizing query response results, etc.

3.4 Start Project

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\ \ \ \_\ \/\ \__//\ \__//\  __//\__, `\/\__, `\
   \ `\____\ \__\ \__/.\_\\ \_\  \ \__\    \ `\____\ \____/\ \____\ \____\ \____\/\____/\/\____/
    \/_____/\/__/\/__/\/_/ \/_/   \/__/     \/_____/\/___/  \/____/\/____/\/____/\/___/  \/___/ 

3.5 Access Projects

  1. Add add add interface swagger
    [External Link Picture Transfer Failure (img-mR4xOBzG-1564208072598) https://github.com/geekidea/spring-boot-plus-doc/blob/master/.vuepress/public/img/sys-log-add-swagger.png?raw=true)]

  2. Delete delete interface swagger
    [External Link Picture Transfer Failure (img-y2VEqMfi-1564208072599) https://github.com/geekidea/spring-boot-plus-doc/blob/master/.vuepress/public/img/sys-log-delete-swagger.png?raw=true)]

  3. getPageList Paging Interface swagger
    [External Link Picture Transfer Failure (img-11tkh1Vj-1564208072599) https://github.com/geekidea/spring-boot-plus-doc/blob/master/.vuepress/public/img/sys-log-getPageList-swagger.png?raw=true)]

  4. info details interface swagger
    [External Link Picture Transfer Failure (img-91Zy7vX0-1564208072600) https://github.com/geekidea/spring-boot-plus-doc/blob/master/.vuepress/public/img/sys-log-info-swagger.png?raw=true)]

  5. update modifies interface swagger
    [External Link Picture Transfer Failure (img-1 REmmQSZ-1564208072600) https://github.com/geekidea/spring-boot-plus-doc/blob/master/.vuepress/public/img/sys-log-update-swagger.png?raw=true)]

Official address: springboot.plus

Topics: Java Spring github Apache