java - @RequestMapping 注解中路径和变量之间的 Spring MVC 差异
问题描述
我想知道课堂上的Spring MVCPath
和Variable
Spring MVC有什么区别Controller
。
@RequestMapping("/home")
@RequestMapping(value = "/home")
@RequestMapping(path = "/home")
基于 Spring Documentation Spring 5 Annotation Type RequestMapping路径是值的别名,值是路径的别名。我想知道这 3 个 RequestMapping 的定义和区别。
解决方案
@RequestMapping("/home") 和 @RequestMapping(value = "/home") 没有区别。但是如果你想添加一些其他参数,那么你必须使用,
@GetMapping(value = "/home/{ABC}", consumes = MediaType.ALL_VALUE)
因为如果写,
@GetMapping("/getTodayActivity/{millis}", consumes = MediaType.ALL_VALUE)
那么它会编译错误,所以只想使用更多参数然后你必须使用“值”
推荐阅读
- c# - EmguCV 3.4.1 中的傅立叶变换
- java - 找不到“org.hibernate.SessionFactory”类型的 bean
- c# - 如何使用 C# 获取基类型类的值
- python - 将字典与整数作为值和键进行比较
- python - Pandas:如何检测数据框中的峰值点(异常值)?
- ajax - Flask Jinja2 页面在一段时间后冻结
- twig - 使用带有 Timber/Twig 的 ACF 库
- vba - 检查多个条件并存储值
- vuejs2 - Nuxt - 定义一次 const 并且可以在所有页面中使用
- javascript - 以“URL/value”形式提交搜索表单,不带查询字符串“?q=value”