标签:ring model springmvc imp 注册 ppi span value print
1) 在默认情况下,springmvc不能将String类型转成java.util.Date类型,所有我们只能在Action
中自定义类型转换器
<form action="${pageContext.request.contextPath}/user/add.action" method="POST"> 编号:<input type="text" name="id" value="${id}"/><br/> 姓名:<input type="text" name="name" value="${name}"/><br/> 薪水:<input type="text" name="sal" value="${sal}"/><br/> 入职时间:<input type="text" name="hiredate" value=‘<fmt:formatDate value="${hiredate}" type="date"/>‘/><br/> <input type="submit" value="注册"/> </form>
@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"; } }
在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型
标签:ring model springmvc imp 注册 ppi span value print
原文地址:https://www.cnblogs.com/loaderman/p/10063300.html