@RequestMapping(value={"/user/{id}/{name}"})
public User getUser(@PathVariable(value="id",required=false) Integer id,@PathVariable(value="name",required=false) String name ){
System.out.println("--------------:"+id+","+name);
User user=new User(id,name);
return user;
}
后面发现上面的文章,将方法改成如下就可以了:
/**
* http://localhost:8080/helloWorld/user/1/zhangsan
* http://localhost:8080/helloWorld/user/1
* http://localhost:8080/helloWorld/user
* @param id
* @param name
* @return
*/
@RequestMapping(value={"/user/{id}/{name}","/user/{id}","/user"})
public User getUser(@PathVariable(value="id",required=false) Integer id,@PathVariable(value="name",required=false) String name ){
System.out.println("--------------:"+id+","+name);
User user=new User(id,name);
return user;
}