日期:2014-05-17 浏览次数:20651 次
public class UserType implements Serializable { private static final long serialVersionUID = 1L; private int id; private String typeName; private String remark; private Date addDate; private Date editDate;
<form name="userTypeForm" method="post" action="create.do"> <fieldset> <legend>用户类型</legend> <p> <label for="typeName">类型名称:</label><br /> <input name="typeName" type="text" value="${userType.typeName }"/> </p> <p> <label for="remark">备注:</label><br /> <input name="remark" type="text" value="${userType.remark }"/> </p> <p> <label for="addDate">添加时间:</label><br /> 2011-9-2 10:19:23 <br /> <input name="addDate" type="text" value="<fmt:formatDate value="${userType.addDate}" type="both" />"/> </p> <p> <label for="editDate">编辑时间:</label><br /> <input name="editDate" type="text" value="<fmt:formatDate value="${userType.editDate}" type="both" />"/> </p> <p> <input type="submit" value="提交"/> </p> </fieldset> </form>
@RequestMapping(value = "create", method = RequestMethod.POST) public String create(@ModelAttribute UserType userType , Model model) {//BindException exception }
/** * Set up a custom property editor for converting form inputs to real objects * * @param request the current request * @param binder the data binder */ @InitBinder public void InitBinder(HttpServletRequest request, ServletRequestDataBinder binder) { // 不要删除下行注释!!! 将来"yyyy-MM-dd"将配置到properties文件中 //SimpleDateFormat dateFormat = new SimpleDateFormat(getText("date.format", request.getLocale())); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true)); }