文章目录
一、全局捕获异常后,返回json给浏览器
项目结构:
1、自定义异常类 MyException.java
package com.gui.restful;
/**
* 自定义异常类
*/
public class MyException extends RuntimeException{
private String code;
private String msg;
public MyException(String code,String msg){
this.code=code;
this.msg=msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
2、控制器 MyController.java
package com.gui.restful;
import org.springframework.web.bind.annotation.RequestMapping;
import org.