关于@PahtVariable和@RequestParam的使用

启:关于我在使用@PathVariable的注解时 但是我请求地址为http://localhost:8002/api/shortlink/v1/user?username=i7

关于@RequestParam以及@PathVariable的使用

其次我不太了解,也是百度查过来的。

其次关于了解

1.当URL指向的是某一具体业务资源(或资源列表),例如博客,不同用户,使用@PathVariable。

2.当URL需要对资源或者资源列表进行筛选过滤,用@RequestParam。

1
2
@RequestMapping(value = “/user/{username}”)
public String userProfile(@PathVariable(value = "username"))
1
2
@RequestMapping(value = "/user")
public String userprofile(@RequestParam(value = "usernmae"))

分别对应的路径为:

1
2
localhost:8002/user/i7
localhost:8002/user?username=i7