IT이야기

주석 @GetMapping과 @RequestMapping의 차이(메서드 = RequestMethod).취득)

cyworld 2022. 6. 5. 19:14
반응형

주석 @GetMapping과 @RequestMapping의 차이(메서드 = RequestMethod).취득)

와의 차이는 무엇입니까?@GetMapping그리고.@RequestMapping(method = RequestMethod.GET)?
스프링 리액티브의 예를 몇 가지 본 적이 있는데@GetMapping대신 사용되었습니다.@RequestMapping

@GetMapping숏컷으로 기능하는 컴포지트 주석입니다.@RequestMapping(method = RequestMethod.GET).

@GetMapping새로운 Annotoion 입니다.소비 지원

사용 옵션은 다음과 같습니다.

= "텍스트/메시지" 소비
= {"text/filename", "application/*"}을(를) 소비합니다.

자세한 내용은 GetMapping Annotation을 참조하십시오.

또는 읽기: 매핑 바리안트 요청

Request Mapping은 소비도 지원합니다.

GetMapping은 메서드 레벨과 RequestMapping 주석에만 적용할 수 있으며 클래스 레벨과 메서드 레벨에도 적용할 수 있습니다.

여기 보시는 바와 같이

구체적으로는@GetMapping숏컷으로 기능하는 컴포지트 주석입니다.@RequestMapping(method = RequestMethod.GET).

의 차이점@GetMapping&@RequestMapping

@GetMapping를 서포트하고 있습니다.consumes같은 특성@RequestMapping.

@RequestMapping클래스 레벨입니다.

@GetMapping메서드 레벨입니다.

스프린트 스프링 4.3 이후로는 상황이 달라졌다.이제 http 요청을 처리하는 메서드에서 @GetMapping을 사용할 수 있습니다.클래스 레벨의 @RequestMapping 사양은 (메서드레벨)을 사용하여 조정됩니다.@Get 주석 매핑

다음은 예를 제시하겠습니다.

@Slf4j
@Controller
@RequestMapping("/orders")/* The @Request-Mapping annotation, when applied
                            at the class level, specifies the kind of requests 
                            that this controller handles*/  

public class OrderController {

@GetMapping("/current")/*@GetMapping paired with the classlevel
                        @RequestMapping, specifies that when an 
                        HTTP GET request is received for /order, 
                        orderForm() will be called to handle the request..*/

public String orderForm(Model model) {

model.addAttribute("order", new Order());

return "orderForm";
}
}

Spring 4.3 이전에는@RequestMapping(method=RequestMethod.GET)

Craig Walls가 쓴 책의 추가 읽기 Craig Walls가 쓴 책의 추가 읽기

간단한 답변:

의미에는 차이가 없습니다.

구체적으로 @GetMapping은 @RequestMapping(메서드=RequestMethod)의 바로 가기 역할을 하는 구성된 주석입니다.GET)

추가 정보:

RequestMapping클래스 레벨에서 사용할 수 있습니다.

이 주석은 클래스와 메서드 수준 모두에서 사용할 수 있습니다.대부분의 경우 응용 프로그램에서는 HTTP 메서드 고유의 바리안트@GetMapping, @PostMapping, @PutMapping, @DeleteMapping 또는 @PatchMapping 중 하나를 사용하는 것이 좋습니다.

하는 동안에GetMapping는 메서드에만 적용됩니다.

HTTP GET 요구를 특정 핸들러 메서드에 매핑하기 위한 주석.


https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/GetMapping.html

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html

  1. @RequestMappingmethod=에서도 소비 지원GET. 단, @GetMapping은 소비를 지원하지 않습니다.
  2. @RequestMapping은 Method & Type 수준의 주석이며 @GetMapping은 Method 수준의 주석입니다.

그 이외의 @GetMapping은 @RequestMapping(method=RequestMethod)과 동일합니다.취득)


                         `@RequestMapping` since 2.5

=> 모든 HTTP 메서드에 대응 가능

=> 클래스 및 방법에 적용 가능

=>대용으로 사용할 수 있습니다.@Controller ★★★★★★★★★★★★★★★★★」@RestController@Component.


                        `@GetMapping` since 4.3

=> HTTP의 GET 메서드만 처리 가능

=> 방법에만 적용 가능

@GetMapping는 의 유형입니다.@RequestMapping(method = RequestMethod.GET) 모두 소비 전력을 양쪽 모두 소비전력

언급URL : https://stackoverflow.com/questions/39077787/difference-between-the-annotations-getmapping-and-requestmappingmethod-requ

반응형