주석 @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)
간단한 답변:
의미에는 차이가 없습니다.
구체적으로 @GetMapping은 @RequestMapping(메서드=RequestMethod)의 바로 가기 역할을 하는 구성된 주석입니다.GET)
추가 정보:
RequestMapping
클래스 레벨에서 사용할 수 있습니다.
이 주석은 클래스와 메서드 수준 모두에서 사용할 수 있습니다.대부분의 경우 응용 프로그램에서는 HTTP 메서드 고유의 바리안트@GetMapping, @PostMapping, @PutMapping, @DeleteMapping 또는 @PatchMapping 중 하나를 사용하는 것이 좋습니다.
하는 동안에GetMapping
는 메서드에만 적용됩니다.
HTTP GET 요구를 특정 핸들러 메서드에 매핑하기 위한 주석.
@RequestMapping
method=에서도 소비 지원GET. 단, @GetMapping은 소비를 지원하지 않습니다.- @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
'IT이야기' 카테고리의 다른 글
"export 'default'('_vue_script__'로 표시됨)를 '!babel-default'에서 찾을 수 없습니다. (0) | 2022.06.05 |
---|---|
Vue2: 루트를 사용하여 다른 페이지로 리다이렉트하는 방법 (0) | 2022.06.05 |
편백으로 vuex 테스트 (0) | 2022.06.05 |
JSDoc을 사용하여 'const z = (y)' = > (a, b = 3) > []'를 문서화하는 방법 (0) | 2022.06.05 |
소품에 대해 단일 인용구를 사용하지 않는 방법 (0) | 2022.06.05 |