Spring注入Date类型的属性,自定义Date属性编辑器
来源:互联网 发布:lnmp php探针 编辑:程序博客网 时间:2024/05/02 00:45
spring中注入时间日期(java.util.Date)类型的属性的时候不能直接注入Date类型,需要进行类型转换。
1、编写UtilDatePropertyEditor类
import java.beans.PropertyEditorSupport; import java.text.SimpleDateFormat; import java.text.ParseException; import java.util.Date; public class UtilDatePropertyEditor extends PropertyEditorSupport { private String format="yyyy-MM-dd"; @Override public void setAsText(String text) throws IllegalArgumentException { System.out.println("UtilDatePropertyEditor.setAsText() -- text=" + text); SimpleDateFormat sdf = new SimpleDateFormat(format); try{ Date d = sdf.parse(text); this.setValue(d); }catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void setFormat(String format) { this.format = format; } }
2、在spring配置文件xml中配置自定属性编辑器
<!-- 配置自定义属性编辑器 --> <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="customEditors"> <map> <entry key="java.util.Date" value="pers.h.finalproject.model.common.UtilDatePropertyEditor"/> </map> </property> </bean>
转自:http://blog.csdn.net/xinyoulin/article/details/52315810
阅读全文
0 0
- Spring注入Date类型的属性,自定义Date属性编辑器
- spring如何注入Date类型的属性
- spring如何注入Date类型的属性
- spring Date属性编辑器
- 对象Date属性的注入(属性编辑器)
- 2.Spring bean常见属性的注入:属性编辑器,String->java.util.Date
- Spring属性注入(普通属性注入,自定义属性编辑器)
- spring属性注入中的date注入异常解决方案
- spring 注入Date 类型的数据
- Date类型的实体类属性中,Date必须是Java.util.Date,而不能是Java.sql.Date
- Spring依赖注入对于Date类型数据的处理
- Spring注入Date类型的数据到Bean中
- Spring、基本类型属性和集合类型属性的注入
- Spring自定义属性编辑器
- Spring自定义属性编辑器
- spring自定义属性编辑器
- Spring自定义属性编辑器
- Spring-----自定义属性编辑器
- 解决nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated问题
- 复数的物理意义
- python3 连接mysql数据库
- Linux C 中的一些基础命令
- 作为一位程序员必须掌握的技术
- Spring注入Date类型的属性,自定义Date属性编辑器
- 腾讯AI Lab副主任俞栋:语音识别研究的四大前沿方向
- Spring MVC 积累-不断更新
- 合并石子
- Java网络编程概述
- JVM学习及堆参数含义
- Leetcode(14)
- C++重载赋值运算符
- UML统一建模语言