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

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

本實例中還涉及到Spring中采用多個配置文件,也涉及到對日期格式的注入-------更加靈活
Date屬性類: DatePropertyInjection.Java
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
<?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
復(fù)制代碼 代碼如下:
<?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
復(fù)制代碼 代碼如下:
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技術(shù)通過Setters方式對日期屬性及日期格式進行IOC注入,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 久久久久久久99精品免费观看 | 国产精人妻无码一区麻豆 | 免费观看高清黄页网址大全 | 中国老太婆xxxxx | 亚洲永久免费视频 | 欧美日韩精品 | 含羞草影院免费区 | 在线AV国产传媒18精品免费 | 男同志vdieos免费 | 国产成人精品综合在线 | 久久久久久九九 | 一区二区三区福利视频 | 日本无码人妻丰满熟妇5G影院 | 夜蒲团之5阳性之教 | 你的欲梦裸身在线播放 | 牛牛在线(正)精品视频 | 国产午夜视频在永久在线观看 | 5g天天影院天天看天天爽 | 偷拍精品视频一区二区三区 | 欧美日韩中文在线字幕视频 | 大香伊人久久精品一区二区 | 诱人的秘书BD在线观看 | 精品国产在线手机在线 | 激情内射亚洲一区二区三区 | 十分钟免费观看大全视频 | 天天躁日日躁狠狠躁中文字幕老牛 | 日本高清天码一区在线播放 | 成人公开免费视频 | 欧美一区二区三区久久综 | 毛片亚洲毛片亚洲毛片 | 男女作爱在线播放免费网页版观看 | 色尼玛亚洲 | 男人一生要读的书 | 欧美日韩看看2015永久免费 | 亚洲 日韩 欧美 国产专区 | 中文字幕AV亚洲精品影视 | 97视频免费在线 | 亚洲精品久久久午夜麻豆 | 久久日韩精品无码一区 | 美女伊人网| 西西人体一级裸片 |