- @InitBinder
- public void InitBinder(WebDataBinder dataBinder)
- {
- dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
- public void setAsText(String value) {
- try {
- setValue(new SimpleDateFormat("yyyy-MM-dd").parse(value));
- } catch(ParseException e) {
- setValue(null);
- }
- }
- public String getAsText() {
- return new SimpleDateFormat("yyyy-MM-dd").format((Date) getValue());
- }
- });
- }
本文详细介绍了如何在Web应用中使用@InitBinder注解注册自定义编辑器来处理日期格式化,通过SimpleDateFormat确保日期字符串与Date对象之间的正确转换。
1159

被折叠的 条评论
为什么被折叠?



