天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

通過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注入,轉載需保留來源!

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

主站蜘蛛池模板: 亚洲欧美强伦一区二区另类 | 色噜噜噜噜亚洲第一 | 给我免费播放片bd国语 | 红尘影院在线观看 | 亚洲娇小性色xxxx | 欧美精品色婷婷五月综合 | 日本无码毛片久久久九色综合 | 久久无码AV亚洲精品色午夜麻豆 | 丰满饥渴老太性hd | 99精品亚洲| 国产情侣真实露脸在线 | 亚洲国产在线综合018 | 灰原哀被啪漫画禁漫 | 国产人人为我我为人人澡 | 久久精品国产亚洲AV忘忧草蜜臀 | 成人女人A级毛片免费软件 成人免费在线视频 | 亚洲午夜精品A片久久不卡蜜桃 | 98久久无码一区人妻A片蜜 | 中文字幕一区二区三区在线观看 | 精品无码久久久久久动漫 | a在线免费观看视频 | 中国毛片网 | 黄色片网站下载 | 成人毛片100部免费看 | WWW夜片内射视频在观看视频 | 亚洲视频在线观看视频 | 秋霞伦理高清视频在线 | WWW国产亚洲精品久久麻豆 | 亚洲精品青青草原avav久久qv | 好嗨哟在线看片免费 | 久久青青无码AV亚洲黑人 | 日本夜爽爽一区二区三区 | 亚洲国产日韩制服在线观看 | 亚洲视频中文字幕在线观看 | 最近中文字幕在线中文视频 | 午夜福利网国产A | 亚洲国产精品特色大片观看 | 曰本老头同性xxxxx | 2022国产麻豆剧传媒剧情 | 不用播放器的黄 | 亚洲一区综合图区 |