リスティングの例


https://loizenai.com/restcontrolleradvice-springboot-example/
チュートリアル:@ RESTControllerAdviceの例題スプリングブート- RESTとRESTのエラー処理.
この記事では、SpringBootの@ restcontroerAdvice注釈について説明します.
続きを読むhttps://loizenai.com/angular-10-spring-boot-jwt-authentication-example/
  • 本稿で使用する技術
    - Java 1.8
    -マヴェン

  • 注釈タイプ
    @ RESTControllerAdviderはSpring Framework 4.3の新しい機能です.したがって@ rerecontroerAdviderはクロスカットの問題解決によってrestfulapiで例外を処理するのに役立ちます.
    @Target(value=TYPE)
     @Retention(value=RUNTIME)
     @Documented
     @ControllerAdvice
     @ResponseBody
    public @interface RestControllerAdvice
    
    適切なhandleMapping HandlerAdapterペアがMVC Java ConfigおよびMVC名前空間の既定であるRequestMappingHandlerMapping RequestMappingHandlerAdapterペアのように構成されている場合は、SrereControerAdviderが処理されます.
    @RestControllerAdvice
    public class WebRestControllerAdvice {
    
      @ExceptionHandler(CustomNotFoundException.class)
      public ResponseMsg handleNotFoundException(CustomNotFoundException ex) {
        ResponseMsg responseMsg = new ResponseMsg(ex.getMessage());
        return responseMsg;
      }
    }
    
    すべての例外を扱うHandleOleBoundExceptionメソッドは、以下のように入力します.
    @RequestMapping(value="/customer/{name}")
    public Customer findCustomerByName(@PathVariable("name")String name){
    
      Customer cust = customerService.findCustomerByName(name);
    
      if(null == cust){
        throw new CustomNotFoundException("Not found customer with name is " + name);
      }
    
      return cust;
    }
    

    関連ポスト
  • Angular 8 SpringBoot MySQL CRUD Example
  • Angular 9 SpringBoot MySQL CRUD Example
  • SpringBoot + Angular 10 PostgreSQL CRUD Example
  • Angular 8 SpringBoot PostgreSQL CRUD Example
  • SpringBoot Angular 9 PostgreSQL CRUD Example
  • Angular 11 SpringBoot CRUD MySQL Example
  • Angular SpringBoot CRUD MySQL Example
  • SpringBoot MongoDB Angular CRUD Example Github
  • How to Integrate Angular 9 with SpringBoot Tutorial
  • YouTube動画