[英]Java Spring @RequestMapping annotation
Why am I able to use this annotation - give it a value without specifying which element I'm assigning this value to? 为什么我可以使用此批注-给它一个值而不指定要将该值分配给哪个元素? For example, I can write:
@RequestMapping("/home")
instead of @RequestMapping(value="/home")
. 例如,我可以编写:
@RequestMapping("/home")
而不是@RequestMapping(value="/home")
。
The specs do not mention anything about it. 规格未提及任何内容。 Is it just a behaviour of Java annotations treating the field
value
as default one? 它只是Java注释将字段
value
视为默认值的一种行为吗?
Case #1: If you have a single value then it's optional to write like this: 情况1:如果您使用单个值,则可以这样编写:
@RequestMapping(value="/home")
In this case you may write @RequestMapping("/home")
also. 在这种情况下,您也可以编写
@RequestMapping("/home")
。 While providing a single string this is automatically assigned to "value". 提供单个字符串时,该字符串会自动分配给“值”。 [ default behavior ]
[默认行为]
Case #2: @RequestMapping has a String[] value parameter, so you should be able to specify multiple values like this: 情况2: @RequestMapping具有String []值参数,因此您应该能够指定多个值,如下所示:
@RequestMapping(value={"","/", "/away", "/home"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.