如何在RedirectView中发送对象

时间:2014-08-12 09:50:22

标签: mongodb spring-mvc model-view-controller spring-data

@Controller
public class PersonController {  
@Autowired  
private PersonService personService;

@RequestMapping(value = "/person", method = RequestMethod.GET)  
public String getPersonList(@ModelAttribute ModelMap model,Person person) {  
    model.addAttribute("personList", personService.listSpecificPerson(person));
    return "output";  //this will redirect to output.jsp
}  

@RequestMapping(value = "/person/save", method = RequestMethod.POST)  
public View createPerson(@ModelAttribute Person person, ModelMap model) {
    if(StringUtils.hasText(person.getId())) {  
        personService.updatePerson(person);  
    } else {  
        person=personService.addPerson(person);  
    }  
    return new RedirectView("/RegistrationSpringWithMongo/person");  
 }  
}  

服务类中的方法:
    public person listSpecificPerson(Person person){
         return mongoTemplate.findById(person.getId(),Person.class,COLLECTION_NAME);
    }

在" createPerson"的返回语句中的上述代码中方法我想传递对象" person"并在" getPersonList"中接收该对象方法并想使用。
任何人请在这方面帮助我。
提前致谢。

1 个答案:

答案 0 :(得分:0)

由于您要将客户端重定向到不同的URL,因此可以使用flash attributes在HTTP请求之间存储“person”对象。