您的位置:首页 > 编程语言 > Java开发

SpringMVC 在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型

2017-03-23 15:51 513 查看
@Controller
@RequestMapping(value = "/user")
public class UserAction {
@InitBinder
protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(
Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(int id, String name, double sal, Date hiredate,
Model model) throws Exception {
System.out.println("HelloAction::add()::POST");
model.addAttribute("id", id);
model.addAttribute("name", name);
model.addAttribute("sal", sal);
model.addAttribute("hiredate", hiredate);
return "/register.jsp";
}
}


@InitBinder
protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(
Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
}


方法名任意
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐