spring mvc的表单类型转换(custom property editor)
spring mvc的表单类型转换太强大了,目前用到了两个简单的, 一个是将表单中的file自动映射成byte[],这样文件上传(如果使用blob)就无需写任何代码了。 另一个是将表单中的yyyy-MM-dd格式映射成java.util.Date, 假设User.java中有如下这两种特殊的属性: public class User implements Serializable{ private Date birth; private byte[] icon; } 注册这两种属性编辑器只需在Controller中定义如下这样一个 initBinder 方法: @Controller("userController") @RequestMapping(value = "/user") public class UserController { @RequestMapping(value = "create", method = RequestMethod.POST) public String create(@ModelAttribute("user") User user, RedirectAttributes redirectAttributes) { userService.createUser(user); redirectAttributes