Programing

주석 @GetMapping과 @RequestMapping의 차이점 (method = RequestMethod.GET)

lottogame 2020. 7. 10. 08:16
반응형

주석 @GetMapping과 @RequestMapping의 차이점 (method = RequestMethod.GET)


차이 무엇 @GetMapping@RequestMapping(method = RequestMethod.GET)?
좀 봄 반응성 예에서 본 적이 @GetMapping대신 사용@RequestMapping


@GetMapping에 대한 단축키 역할을하는 구성된 주석입니다 @RequestMapping(method = RequestMethod.GET).

@GetMapping새로운 Annotaion입니다. 그것은 소비를 지원합니다

소비 옵션은 다음과 같습니다.

소비 = "text / plain"
소비 = { "text / plain", "application / *"}

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

또는 읽기 : 요청 매핑 변형

RequestMapping은 소비도 지원합니다


당신이 볼 수 있듯이 여기 :

특히, @GetMapping에 대한 바로 가기 역할을하는 구성된 주석입니다 @RequestMapping(method = RequestMethod.GET).

@GetMapping&의 차이점@RequestMapping

@GetMappingconsumes와 같은 속성을 지원합니다 @RequestMapping.


@RequestMapping 수업 수준입니다

@GetMapping 방법 수준입니다

스프린트 봄 4.3. 그리고 위로 물건이 바뀌었다. 이제 http 요청을 처리 할 메소드에서 @GetMapping을 사용할 수 있습니다. 클래스 레벨 @RequestMapping 스펙은 (메소드 레벨) @GetMapping 주석으로 세분화됩니다.

예를 들면 다음과 같습니다.

@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가 저술 한 책에서 추가로 읽음 Extra reading from a book authored by Craig Walls


짧은 답변:

시맨틱에는 차이가 없습니다.

특히 @GetMapping은 @RequestMapping (method = RequestMethod.GET) 의 바로 가기 역할을 하는 구성된 주석입니다 .

더 읽을 거리 :

RequestMapping 수업 레벨에서 사용할 수 있습니다 :

This annotation can be used both at the class and at the method level. In most cases, at the method level applications will prefer to use one of the HTTP method specific variants @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, or @PatchMapping.

while GetMapping only applies to method:

Annotation for mapping HTTP GET requests onto specific handler methods.


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

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

반응형