在 Spring MVC
中,@PathVariable("ownerId") String theOwner
和 @PathVariable String theOwner
之间有什么区别吗?
我已经完成了 Spring @PathVariable ,但我不清楚这个概念。
我通过分析 uri parameter
是否与 variable name
同名发现了一个区别,那么你可以直接将它存储在变量中。这是否正确,或者您可以发布与此相关的任何其他信息。
@GetMapping("/owners/{ownerId}")
public String findOwner(@PathVariable("ownerId") String theOwner, Model model) {
// implementation omitted
}
@GetMapping("/owners/{ownerId}")
public String findOwner(@PathVariable String ownerId, Model model) {
// implementation omitted
}
最佳答案
唯一的区别是第一个选项允许您更改方法中的参数名称,您可以使用 theOwner
而不是 ownerId
。
这可能很有用,例如,如果您有一个同名的类成员 ownerId
关于java - @PathVariable ("ownerId") String theOwner 和@PathVariable String theOwner 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45832653/