mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 05:48:33 +08:00
fix GlobalDefaultExceptionHandler
This commit is contained in:
parent
e9b7e9c477
commit
abaaa40965
@ -1,12 +1,11 @@
|
|||||||
package com.softdev.system.generator.config;
|
package com.softdev.system.generator.config;
|
||||||
|
|
||||||
import com.softdev.system.generator.entity.ReturnT;
|
import com.softdev.system.generator.entity.vo.ResultVo;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhengkai.blog.csdn.net
|
* @author zhengkai.blog.csdn.net
|
||||||
*/
|
*/
|
||||||
@ -15,9 +14,9 @@ public class GlobalDefaultExceptionHandler {
|
|||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ReturnT defaultExceptionHandler(HttpServletRequest req, Exception e) {
|
public ResultVo defaultExceptionHandler(HttpServletRequest req, Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return ReturnT.error("代码生成失败:"+e.getMessage());
|
return ResultVo.error("代码生成失败:"+e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,65 +0,0 @@
|
|||||||
package com.softdev.system.generator.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* common returnT:公共返回封装类
|
|
||||||
*
|
|
||||||
* @author zhengkai.blog.csdn.net
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class ReturnT extends HashMap<String, Object> {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public ReturnT() {
|
|
||||||
put("code", 0);
|
|
||||||
put("msg", "success");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ReturnT error() {
|
|
||||||
return error(500, "未知异常,请联系管理员");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ReturnT error(String msg) {
|
|
||||||
return error(500, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ReturnT error(int code, String msg) {
|
|
||||||
ReturnT r = new ReturnT();
|
|
||||||
r.put("code", code);
|
|
||||||
r.put("msg", msg);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
public static ReturnT define(int code, String msg) {
|
|
||||||
ReturnT r = new ReturnT();
|
|
||||||
r.put("code", code);
|
|
||||||
r.put("msg", msg);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
public static ReturnT ok(String msg) {
|
|
||||||
ReturnT r = new ReturnT();
|
|
||||||
r.put("msg", msg);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ReturnT ok(Map<String, Object> map) {
|
|
||||||
ReturnT r = new ReturnT();
|
|
||||||
r.putAll(map);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ReturnT ok() {
|
|
||||||
return new ReturnT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ReturnT put(String key, Object value) {
|
|
||||||
super.put(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user