SpringBoot学习记录
常见的问题
这是一篇测试markdown文件
- 无敌是多么寂寞
- 啊啊啊啊
- 大无畏
- yes this
- 我也没不知u
package com.test.exception;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestControllerAdvice
public class GlobalExceptionHandler {
//处理普通系统异常
@ExceptionHandler(value = Exception.class)
public R systemException(Exception e){
e.printStackTrace();
System.out.println("==================================>>"+e.getMessage()+"=================================");
return new R(false,null,"系统内部异常,请联系管理员");
}
@ExceptionHandler(value = MyExceptionHandler.class)
public ResponseEntity<R> myException(MyExceptionHandler e){
e.printStackTrace();
ResponseEntity<R> responseEntity;
switch (e.getCode()){
case 403:
responseEntity = ResponseEntity.status(HttpStatus.FORBIDDEN).body(new R(e.getMsg()));
break;
case 404:
responseEntity = ResponseEntity.status(HttpStatus.NOT_FOUND).body(new R(e.getMsg()));
break;
default:
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new R(e.getMsg()));
break;
}
return responseEntity;
}
}
呜呜呜 | 沃达丰 | 安放在福娃发 |
---|---|---|
111 | 222 | 33333 |
111 | 222 | 3333333333333 |
2222 | 44444 | 555555 |