As I wrote in another article, I didn't touch Java very much during the heyday of annotation (?), So I didn't understand the argument rules of annotation well, and even if I googled, there was nothing that met the demand, so I will write it myself. For those who have the same question in the future.
Below, the annotation shown in the example uses @RequestMapping.
It may not be accurate, but I use it in this sense below.
Looking at the reference of @RequestMapping
, some elements are written, but since the default values are all specified, you can write as follows. The default value for each element is used.
@RequestMapping
The following have the same meaning
@RequestMapping(value = "/")
@RequestMapping("/")
In the case of Spring, @AliasFor
is prepared, and the place where" What does the value of Mapping mean? "Can be written as path. See the reference for which element is an alias for value. I think that something that is almost as perceived is another name.
@RequestMapping(path = "/")
The compiler extends it to an array.
// value -> {"/"}
@RequestMapping("/")
You may or may not write your own {}. However, {} is required when writing two or more arguments as explained below.
// value -> {"/", "/index"}
@RequestMapping("/", "/index")
// value -> {"/", "/index"}
@RequestMapping({"/", "/index"})
It was hard to understand because I thought it was like a required argument and an optional argument like Python's default value argument.
@RequestMapping(value = "/", method = RequestMethod.GET)
//I want to decorate Python I can't write as follows
@RequestMapping("/", method = RequestMethod.GET)
Recommended Posts