如何防止 Spring 3.0 MVC @ModelAttribute变量出现在 URL 中?
2022-08-31 17:29:21
使用Spring MVC 3.0.0.RELEASE,我有以下控制器:
@Controller
@RequestMapping("/addIntake.htm")
public class AddIntakeController{
private final Collection<String> users;
public AddIntakeController(){
users = new ArrayList<String>();
users.add("user1");
users.add("user2");
// ...
users.add("userN");
}
@ModelAttribute("users")
public Collection<String> getUsers(){
return this.users;
}
@RequestMapping(method=RequestMethod.GET)
public String setupForm(ModelMap model){
// Set up command object
Intake intake = new Intake();
intake.setIntakeDate(new Date());
model.addAttribute("intake", intake);
return "addIntake";
}
@RequestMapping(method=RequestMethod.POST)
public String addIntake(@ModelAttribute("intake")Intake intake, BindingResult result){
// Validate Intake command object and persist to database
// ...
String caseNumber = assignIntakeACaseNumber();
return "redirect:intakeDetails.htm?caseNumber=" + caseNumber;
}
}
控制器从从 HTML 表单填充的命令对象读取接收信息,验证命令对象,将信息保存到数据库中,并返回事例编号。
一切都很好,除了当我重定向到ingressingDetails.htm页面时,我得到一个如下所示的URL:
http://localhost:8080/project/intakeDetails.htm?caseNumber=1&users=user1&users=user2&users=user3&users=user4...
如何防止用户集合显示在 URL 中?