spring mvc 3.1中 @PathVariable的两个增强

  留意到spring mvc 3.1中 @PathVariable的两个增强,其中:

1)
@RequestMapping("/people/{firstName}/{lastName}/SSN")
public String find(Person person,
                   @PathVariable String firstName,
                   @PathVariable String lastName) {
    person.setFirstName(firstName);
    person.setLastName(lastName);
  
}


  这个在旧的版本中,要强制进行set,在新版本中,不用这样set了,可以这样:
@RequestMapping("/people/{firstName}/{lastName}/SSN")
public String search(Person person) {
   // person.getFirstName() and person.getLastName() are populated
   
}


  

2) redirect中也可以和@PathVariable中一致了,原来的
 
@RequestMapping(
    value="/groups/{group}/events/{year}/{month}/{slug}/rooms",
    method=RequestMethod.POST)
public String createRoom(
    @PathVariable String group, @PathVariable Integer year,
    @PathVariable Integer month, @PathVariable String slug) {
    // ...
    return "redirect:/groups/" + group + "/events/" + year + "/" + month + "/" + slug;
}


  现在:
 
@RequestMapping(
    value="/groups/{group}/events/{year}/{month}/{slug}/rooms",
    method=RequestMethod.POST)
public String createRoom(
    @PathVariable String group, @PathVariable Integer year,
    @PathVariable Integer month, @PathVariable String slug) {
    // ...
    return "redirect:/groups/{group}/events/{year}/{month}/{slug}";
}

你可能感兴趣的:(@PathVariable)