首页 > 解决方案 > @RequestMapping 注解中路径和变量之间的 Spring MVC 差异

问题描述

我想知道课堂上的Spring MVCPathVariableSpring MVC有什么区别Controller

@RequestMapping("/home")
@RequestMapping(value = "/home")
@RequestMapping(path = "/home")

基于 Spring Documentation Spring 5 Annotation Type RequestMapping路径是值的别名,值是路径的别名。我想知道这 3 个 RequestMapping 的定义和区别。

标签: javaspringspring-mvcannotationsrequest-mapping

解决方案


@RequestMapping("/home") 和 @RequestMapping(value = "/home") 没有区别。但是如果你想添加一些其他参数,那么你必须使用,

@GetMapping(value = "/home/{ABC}", consumes = MediaType.ALL_VALUE)

因为如果写,

@GetMapping("/getTodayActivity/{millis}", consumes = MediaType.ALL_VALUE)

那么它会编译错误,所以只想使用更多参数然后你必须使用“值”


推荐阅读