This is the 13th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Spring Boot API Project Seed Plus

Source: github.com/lihengming/…

Demonstrate the GIF

Github.com/tyronczt/sp…

Step 1: Download the source code

Github.com/tyronczt/sp…

Step 2: Configure the database

Import table

DROP TABLE IF EXISTS `t_user_info`;
CREATE TABLE `t_user_info`  (
  `id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'id',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'name',
  `sex` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'gender',
  `age` int(11) NULL DEFAULT NULL COMMENT 'age',
  `job` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'work',
  `create_time` datetime(0) NULL DEFAULT NULL COMMENT 'Added time',
  `update_time` datetime(0) NULL DEFAULT NULL COMMENT 'Update Time'.PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'User Information' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of t_user_info
-- ----------------------------
INSERT INTO `t_user_info` VALUES ('1'.'Joe'.'male'.32.'teachers'.'the 2020-04-18 16:00:55'.NULL);
INSERT INTO `t_user_info` VALUES ('2'.'bill'.'woman'.22.'students'.'the 2020-04-18 16:01:40'.NULL);
INSERT INTO `t_user_info` VALUES ('3'.'Zhang Shasha'.'woman'.35.'lawyers'.'the 2020-04-18 16:02:15'.NULL);
INSERT INTO `t_user_info` VALUES ('4'.'ucg'.'male'.33.'Architect'.'the 2020-04-18 16:03:01'.NULL);

SET FOREIGN_KEY_CHECKS = 1;
Copy the code

Modify the data source and table name in the project

application-dev.yml

spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/user? useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    driver-class-name: com.mysql.cj.jdbc.Driver
Copy the code

spring-boot-00-seed-plus\src\main\java\com\tyron\core\Constant.java

//JDBC configuration, please change to the actual configuration of your project
public static final String JDBC_URL = "jdbc:mysql://localhost:3306/user? useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC";
public static final String JDBC_USERNAME = "root";
public static final String JDBC_PASSWORD = "123456";
public static final String JDBC_DIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
Copy the code

Step 3: Test by executing the main method

Execute main method

spring-boot-00-seed-plus\src\test\java\com\tyron\project\CodeGenerator.java

public static void main(String[] args) {
	genCodeByCustomModelName("t_user_info"."TUserInfo"."User Information"); } TUserinfo.java is generated successfully TUserInfomapper. Java is generated successfully TUserInfomapper. XML is generated successfully tUserInfoService.java is generated successfully TUserInfoServiceImpl. Java to generate successful TUserInfoController. Java to generate successCopy the code

Testing CRUD

1. Start the project

2. Check swagger

http://localhost:7080/swagger-ui.html#

3. Mybatis-Plus test

 @Resource
 private TUserInfoMapper tUserInfoMapper;

@GetMapping("mybatisplustest")
    public Result mybatisPlusTest(a) {
        List<TUserInfo> users = tUserInfoMapper.selectList(new QueryWrapper<TUserInfo>().lambda().like(TUserInfo::getName, "Chen").lt(TUserInfo::getAge, 40));
        return ResultGenerator.genSuccessResult(users);
    }
Copy the code

Note: Test reason, directly write Mapper in controller, normally need to write in service, or directly call Mybatis-Plus built-in service method

Changes that

  • Add Mybatis-Plus plug-in, detailed usage can refer to: Mybatis-Plus quick start at the end of the upgrade version
  • Increase Swagger’s support
  • Add comment fields to the main method
public static void main(String[] args) {
	genCodeByCustomModelName("t_user_info"."TUserInfo"."User Information");
}
Copy the code
  • Adding a module field
public static final String MODEL_PACKAGE = ".user";// Module name, optional
Copy the code