spring-boot-plus V1.2.2 发布,5 Minutes Finish CRUD

673 阅读2分钟

更新日志 CHANGELOG

[V1.2.2-RELEASE] 2019.08.26 🏇

⭐️ New Features

  • 拦截器启用禁用配置
  • 文件上传下载安全/权限控制
  • 启用 logback.xml 日志配置

⚡️ Optimization

  • 更改core包目录
  • 下载上传拦截器
  • logback.xml显示行号
  • application.yml 拦截器配置新增 include-path 拦截路径配置

📝 Added/Modified

  • Add UploadInterceptor 文件上传全局拦截器
  • Add DownloadInterceptor 文件下载全局拦截器
  • Add DownloadHandler DefaultDownloadHandler 文件下载回调自定义处理器
  • Modify config/WebMvcConfig --> core/SpringBootPlusWebMvcConfig
  • Modify ImageController --> ResouceController,请求路径 /api/resource
  • Add SysUser CRUD

🐞 Bug Fixes

  • Fix 文件下载路径潜在安全漏洞,过滤 ../ 非法路径参数
  • Fix 优化文件下载,Firefox 中文乱码问题

📔 Documentation

🔨 Dependency Upgrades

  • pom.xml 使用 spring-boot-starter-validation 替换 hibernate-validator 依赖

5分钟完成增删改查

1. 创建数据库表

-- ----------------------------
-- Table structure for sys_user
-- ----------------------------
drop table if exists `sys_user`;
create table sys_user(
    id          bigint                              not null comment '主键',
    name        varchar(20)                         null comment '用户名称',
    account     varchar(20)                         not null comment '账号',
    pwd         varchar(20)                         not null comment '密码',
    remark      varchar(200)                        null comment '备注',
    create_time timestamp default CURRENT_TIMESTAMP null comment '创建时间',
    update_time timestamp                           null comment '修改时间',
    primary key (`id`),
    constraint sys_user_account_uindex
        unique (account)
) comment '系统用户';
-- ----------------------------
-- Records of sys_user
-- ----------------------------
INSERT INTO sys_user (id, name, account, pwd, remark, create_time, update_time) VALUES (1, 'Administrator', 'admin', '123456', 'Administrator Account', '2019-08-26 00:52:01', null);

2.使用代码生成器生成增删改查代码

修改数据库信息

修改组件名称/作者/数据库表名称/主键id

/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java
/**
 * spring-boot-plus代码生成器入口类
 * @author geekidea
 * @date 2018-11-08
 */
public class CodeGenerator {
    private static final String USER_NAME = "root";
    private static final String PASSWORD = "root";
    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";   
    // CODE... 
    // ############################ 配置部分 start ############################
    // 模块名称
    private static final String MODULE_NAME = "system";
    // 作者
    private static final String AUTHOR = "geekidea";
    // 生成的表名称
    private static final String TABLE_NAME = "sys_user";
    // 主键数据库列名称
    private static final String PK_ID_COLUMN_NAME = "id";
    // 代码生成策略 true:All/false:SIMPLE
    private static final boolean GENERATOR_STRATEGY = true;
    // 分页列表查询是否排序 true:有排序参数/false:无
    private static final boolean PAGE_LIST_ORDER = false;
    // ############################ 配置部分 end ############################
    
    public static void main(String[] args) {
        // Run...
    }
}

3. 启动项目

项目入口类

/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java
/**
 * spring-boot-plus 项目启动入口
 * @author geekidea
 * @since 2018-11-08
 */
@EnableAsync
@EnableScheduling
@EnableTransactionManagement
@EnableConfigurationProperties
@EnableAdminServer
@MapperScan({"io.geekidea.springbootplus.**.mapper"})
@SpringBootApplication
public class SpringBootPlusApplication {

    public static void main(String[] args) {
        // 启动spring-boot-plus
        ConfigurableApplicationContext context = SpringApplication.run(SpringBootPlusApplication.class, args);
        // 打印项目信息
        PrintApplicationInfo.print(context);
    }

}

4. 访问项目swagger文档

http://127.0.0.1:8888/swagger-ui.html

5. 系统用户 增删改查分页Swagger

sys_user_swagger-zh.png