springmvc常用注解配置说明@PathVariable等
URL中的变量――PathVariable 在Web应用中URL通常不是一成不变的,例如微博两个不同用户的个人主页对应两个不同的URL: http://weibo.com/user1 和 http://weibo.com/user2。 我们不可能对于每一个用户都编写一个被 @RequestMapping 注解的方法来处理其请求,Spring MVC提供了一套机制来处理这种情况: @RequestMapping("/users/{username}") public String userProfile(@PathVariable("username") String username) { return String.format("user %s", username); } @RequestMapping("/posts/{id}") public String post(@PathVariable("id") int id) { return String.format("post %d", id); } 在上述例子中,URL中的变量可以用 {variableName} 来表示,同时在方法的参数中加上 @PathVariable("variableName") ,那么当请求被转发给该方法处理时,对应的URL中的变量会被自动赋值给被 @PathVariable 注解的参数