每次修改了代码都需要重新运行才可以生效,刚开始代码量少速度还能接受,后面代码量多了,重新运行的速度比较慢,所以需要使用到热加载。
关于热加载,有商业版的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。



