public interface IOther {
void setString(String string) ;
}
import java.beans.PropertyEditorSupport; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Field; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationEvent; public class Other implements IOther { private String string; public Other() { // TODO Auto-generated constructor stub } public Other(String string) { this.string = string; System.out.println(string); } public String getString() { return string; } public void setString(String string) { this.string = string; System.out.println(string); } }
import java.beans.PropertyEditorSupport; import java.util.Calendar; public class DateEditor extends PropertyEditorSupport { @Override public void setAsText(String text) throws IllegalArgumentException { if (text.matches("[0-9]{4}-[0-9]{2}-[0-9]{2}")) { String[] strings=text.split("-"); int year=Integer.parseInt(strings[0]); int month=Integer.parseInt(strings[1])-1; int day=Integer.parseInt(strings[2]); Calendar calendar=Calendar.getInstance(); calendar.set(year,month,day); setValue(calendar.getTime()); } } }
本文介绍了一个Java类实现字符串到日期的转换,通过Property编辑器支持日期输入的功能,展示了如何自定义日期输入方式,提高了用户体验。
878

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



