spring自定义属性编辑器
程序员文章站
2022-05-26 18:29:20
...
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;
}
}
<!-- 定义属性编辑器 -->
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Date">
<bean class="com.bjsxt.spring.UtilDatePropertyEditor">
<property name="format" value="yyyy-MM-dd"/>
</bean>
</entry>
</map>
</property>
</bean>
上一篇: 最受欢迎的3种水果(综合应用)
下一篇: 超好用的日期控件
推荐阅读
-
spring为java.util.Properties类型的属性进行赋值过程解析
-
spring级联属性赋值的两种方式解析
-
完美实现保存和加载easyui datagrid自定义调整列宽位置隐藏属性功能
-
spring boot tomcat jdbc pool的属性绑定
-
详解HTML5 data-* 自定义属性
-
vue.js 获取当前自定义属性值
-
你知道@RequestMapping的name属性有什么用吗?【享学Spring MVC】
-
[Spring Boot]使用自定义注解统一请求返回值
-
JSP自定义标签-标签属性_动力节点Java学院整理
-
HTML5的自定义属性data-*详细介绍和JS操作实例