一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

通過Setters方式對日期屬性及日期格式進行IOC注入

本實例中還涉及到Spring中采用多個配置文件,也涉及到對日期格式的注入-------更加靈活
Date屬性類: DatePropertyInjection.Java
復制代碼 代碼如下:
package com.zhmg.spring;
import Java.util.Date;
public class DatePropertyInjection {
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}

屬性編輯器類:PropertyEditor.Java
復制代碼 代碼如下:
package com.zhmg.spring;
import Java.beans.PropertyEditorSupport;
import Java.text.ParseException;
import Java.text.SimpleDateFormat;
import Java.util.Date;
/**
* 自定義屬性編輯器處理Java.util.Date類型的屬性
* @author Administrator
*
*/
public class PropertyEditor extends PropertyEditorSupport {
String format = "yyyy-MM-dd";
public void setFormat(String format) {
this.format = format;
}
@Override
public void setAsText(String arg0) throws IllegalArgumentException {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
try {
Date date = dateFormat.parse(arg0);
this.setValue(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

applicationContextBeans.xml
復制代碼 代碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dateProperty" class="com.zhmg.spring.DatePropertyInjection">
<property name="date">
<value>2009-8-28</value>
</property>
</bean>
</beans>

applicationContextBeans.xml
復制代碼 代碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!--
<bean id="dateProperty" class="com.zhmg.spring.DatePropertyInjection">
<property name="date">
<value>2009-8-28</value>
</property>
</bean>
-->
<bean id="editor" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="Java.util.Date">
<bean class="com.zhmg.spring.PropertyEditor">
<!―對日期格式注入-->
<property name="format" value="yyyy-MM-dd"/>
</bean>
</entry>
</map>
</property>
</bean>
</beans>

測試單元:InjectionTest.Java
復制代碼 代碼如下:
package com.zhmg.spring;
import junit.framework.TestCase;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class InjectionTest extends TestCase {
BeanFactory factory;
protected void setUp() throws Exception {
//采用通配符的方式讀取所有以applicationContext開頭的配置文件
factory = new ClassPathXmlApplicationContext("applicationContext*.xml");
}
public void testInjection(){
DatePropertyInjection dateProp = (DatePropertyInjection)factory.getBean("dateProperty");
System.out.println("date=" + dateProp.getDate());
}
}

jsp技術通過Setters方式對日期屬性及日期格式進行IOC注入,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 精品日韩一区二区 | 美女三级福利视频 | 99精品久久精品一区二区 | 国产精品视频第一区二区三区 | 99精品国产福利在线观看 | 一本大道久久香蕉成人网 | 成年美女网站 | 亚洲精品乱码国产精品乱码 | riav久久中文一区二区 | 色网站在线观看 | 99国产精品欧美久久久久久影院 | 麻豆精品国产自产在线 | 91久久99久91天天拍拍 | 欧美日韩亚洲国产一区二区综合 | 国产99在线播放 | 日日噜噜夜夜狠狠tv视频免费 | 国产一区二区三区高清视频 | 一区二区三区四区视频 | 国产91一区二区在线播放不卡 | 亚洲深爱 | 黄色网址免费在线播放 | 国产伦精品一区二区三区免费迷 | 国产人成精品 | 精品国产一区二区三区四 | 激情婷婷丁香 | 精品亚洲综合在线第一区 | 精品亚洲国产国拍 | 亚洲一道本 | 免费在线观看色 | 在线观看视频一区 | 18女人腿打开无遮掩免费 | 免费精品久久久久久中文字幕 | 久久精品国产99久久无毒不卡 | 色网站在线观看 | 国产精品视频一区二区猎奇 | 中国嫩模一级毛片 | 亚洲a在线观看 | 国产精品自拍亚洲 | 国产成人短视频 | 最近中文字幕无吗免费高清 | 久久久久中文 |