java – Spring MVC Diffrence between Path & Variable in @RequestMapping Annotation
java – Spring MVC Diffrence between Path & Variable in @RequestMapping Annotation
Theres no difference between @RequestMapping(/home) and @RequestMapping(value = /home).But if you want to add some other parameter then you have to use,
@GetMapping(value = /home/{ABC}, consumes = MediaType.ALL_VALUE)
because if write,
@GetMapping(/getTodayActivity/{millis}, consumes = MediaType.ALL_VALUE)
then it will compile error, so only want to use more parameter then you have to use value
According to this there is no difference between @RequestMapping(/home)
and @RequestMapping(value = /home)
when you are using to class level or method level.
However, you can use pass more than one variable with this usage @RequestMapping(value={/method1,/method1/second})
java – Spring MVC Diffrence between Path & Variable in @RequestMapping Annotation
Theres no difference between @RequestMapping(/home)
and @RequestMapping(value = /home)
. You can quickly use the former if theres only one mapping, and latter if there are multiple URLs that are being mapped to same place, for example, @RequestMapping(value={/home,/home2,/home2/home3})
Similarly, the path and value are also same. If you look at their definitions, they are basically alias of each other:
definition of value:
@AliasFor(value=path)
public abstract java.lang.String[] value
...
definition of path:
@AliasFor(value=value)
public abstract java.lang.String[] path
...
As for all the definitions, you can always visit the official docs.