栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot学习3-热部署热加载/请求反馈

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot学习3-热部署热加载/请求反馈

每次修改了代码都需要重新运行才可以生效,刚开始代码量少速度还能接受,后面代码量多了,重新运行的速度比较慢,所以需要使用到热加载。
关于热加载,有商业版的JRebel and XRebel插件可以使用,在插件中心安装完了重启IDE即可在右上角看见运行按钮,缺点就是要钱,也可以使用通用的devtools来实现,首先需要在pom里面加入依赖:


	org.springframework.boot
	spring-boot-devtools
	true

新版的IDE需要在设置里的高级设置开启自动make:

接着,我们可以运行项目,然后修改代码后,即可点击右上角小锤子来进行热加载

请求反馈

统一新建一个类,StatusReponse

package com.example.demo.controller;

import lombok.Data;

@Data
public class StatusReponse {

    //是否成功
    private boolean success;
    //状态码
    private int code;
    //状态消息
    private String msg;
    //附加数据
    private Object data;

    StatusReponse(){};

    
    public static StatusReponse success()
    {
        StatusReponse ajaxResponse = new StatusReponse();
        ajaxResponse.setCode(200);
        ajaxResponse.setSuccess(true);
        ajaxResponse.setMsg("查询成功");
        return ajaxResponse;
    }

    public static StatusReponse success(String msg,int code)
    {
        StatusReponse StatusReponse = new StatusReponse();
        StatusReponse.setCode(code);
        StatusReponse.setSuccess(true);
        StatusReponse.setMsg(msg);
        return StatusReponse;
    }

    public static StatusReponse success(Object data,String msg,int code)
    {
        StatusReponse StatusReponse = new StatusReponse();
        StatusReponse.setCode(code);
        StatusReponse.setData(data);
        StatusReponse.setSuccess(true);
        StatusReponse.setMsg(msg);
        return StatusReponse;
    }

    public static StatusReponse success(Object data,String msg)
    {
        StatusReponse StatusReponse = new StatusReponse();
        StatusReponse.setCode(200);
        StatusReponse.setData(data);
        StatusReponse.setSuccess(true);
        StatusReponse.setMsg(msg);
        return StatusReponse;
    }

    
    public static StatusReponse faild(int code)
    {
        StatusReponse StatusReponse = new StatusReponse();
        StatusReponse.setCode(code);
        StatusReponse.setSuccess(false);
        return StatusReponse;
    }

    public static StatusReponse faild(int code,String msg)
    {
        StatusReponse StatusReponse = new StatusReponse();
        StatusReponse.setCode(500);
        StatusReponse.setMsg(msg);
        StatusReponse.setSuccess(false);
        return StatusReponse;
    }

    public static StatusReponse faild()
    {
        StatusReponse StatusReponse = new StatusReponse();
        StatusReponse.setCode(500);
        StatusReponse.setSuccess(false);
        return StatusReponse;
    }
}

控制器使用StatusReponse.success(data,"查询成功");即可输出相关JSON。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/865316.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号