Sring boot项目实战

本文记录了Spring Boot项目的实践,包括构建Maven+Spring Boot多模块项目,创建目录结构,建立统一响应模型,使用Lombok提高效率,配置日志系统,创建统一校验工具类以及全局异常处理类。这些工具类旨在简化开发流程。
摘要由CSDN通过智能技术生成

个人学习记录

本篇博客仅记录个人的学习记录,仅考虑本人自己观看

构建Maven +springboot 多模块的项目

根据多模块项目图结合Maven构建出Springboot开发项目。
在这里插入图片描述

创建项目的目录结构

在这里插入图片描述
对面pom.xml就导入响应模块的jar,在server创建响应 的入口类

@SpringBootApplication
@ImportResource(value = {
   "classpath:spring/spring-jdbc.xml"})
@MapperScan(basePackages = "org.example.model.mapper")
public class MainApplication extends SpringBootServletInitializer {
   
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
   
        return builder.sources(MainApplication.class);
    }

    public static void main(String[] args) {
   
        SpringApplication.run(MainApplication.class,args);
    }
}
之后能运行起来 就算是基本的项目环境创建完毕

创建前后端统一响应模型

创建枚举类 在api模块下
在这里插入图片描述

public enum StatusCode {
   
    success(0,"成功"),
    fail(-1,"失败"),
    InvalidParams(201,"非法参数"),
    ;
    private Integer code;
    private String  msg;

    StatusCode(Integer code, String msg) {
   
        this.code = code;
        this.msg = msg;
    }

   //get set方法省略
}

随后创建统一的响应类

public class BaseResponse<T> {
   
    private Integer code;
    private String msg;
    private T date;
      public BaseResponse(Integer code, String msg, T date) 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值