---
title: "spring自定义属性编辑器"
author: "gyht0808"
date: "2009-10-13T17:24:42Z"
tags: ["Java", "Spring", "XML"]
slug: "spring"
draft: false
lastmod: "2009-10-13T17:24:42Z"
id: 487167
url: "https://gyht0808.iteye.com/blog/487167"
---

\[code="java"]public class UtilDatePropertyEditor extends PropertyEditorSupport { private String format="yyyy-MM-dd"; @Override public void setAsText(String text) throws IllegalArgumentException { System.out.println("UtilDatePropertyEditor.saveAsText() -- text=" + text); SimpleDateFormat sdf = new SimpleDateFormat(format); try { Date d = sdf.parse(text); this.setValue(d); } catch (ParseException e) { e.printStackTrace(); } } public void setFormat(String format) { this.format = format; } }\[/code] \[code="xml"] \[/code]