now*_*y94 130 java spring spring-mvc spring-4
@GetMapping和之间有什么区别@RequestMapping(method = RequestMethod.GET)?
我在一些Spring Reactive示例中看到过,
@GetMapping而不是使用它@RequestMapping
dhS*_*dhS 176
@GetMapping是一个组合注释,充当快捷方式@RequestMapping(method = RequestMethod.GET).
@GetMapping是较新的注释.它支持消费
消费选项包括:
consumes ="text/plain"
consumes = {"text/plain","application/*"}
有关详细信息,请参阅: GetMapping Annotation
或阅读: 请求映射变体
RequestMapping也支持消费
简短的回答:
语义上没有区别。
具体来说,@GetMapping 是一个组合注解,作为@RequestMapping(method = RequestMethod.GET)的快捷方式。
进一步阅读:
RequestMapping 可以在类级别使用:
这个注解可以在类和方法级别使用。在大多数情况下,在方法级别应用程序更喜欢使用 HTTP 方法特定变体 @GetMapping、@PostMapping、@PutMapping、@DeleteMapping 或 @PatchMapping 之一。
whileGetMapping仅适用于方法:
用于将 HTTP GET 请求映射到特定处理程序方法的注释。
@RequestMapping 是班级
@GetMapping 在方法级别
使用sprint Spring 4.3。一切都变了。现在,您可以在将处理http请求的方法上使用@GetMapping。使用(方法级别)@GetMapping注释完善了类级别的@RequestMapping规范
这是一个例子:
@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";
}
}
Run Code Online (Sandbox Code Playgroud)
在Spring 4.3之前,它是 @RequestMapping(method=RequestMethod.GET)
克雷格·沃尔斯(Craig Walls)撰写的书中的额外读物

| 归档时间: |
|
| 查看次数: |
92430 次 |
| 最近记录: |