ControllerAdvice

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;
@ControllerAdvice
public class MayiktExceptionHandler {

  @ExceptionHandler({RuntimeException.class})
  @ResponseBody
  public Map<String,String> exceptionHandler(){
    HashMap<String,String > objectObjectHashMap=new HashMap<>();
    objectObjectHashMap.put("respCode","500");
    objectObjectHashMap.put("respMsg","系统错识");
    return objectObjectHashMap;
  }
}

 

 


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

  @RestController
  public class TestContoller {

    @RequestMapping("/test1")
    public String test1(String username,Integer age){
      int j=1/age;
      return "error";
    }

}

相关文章:

  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-23
  • 2022-01-30
  • 2021-10-22
  • 2022-01-20
相关资源
相似解决方案