欢迎来到天天文库
浏览记录
ID:11530410
大小:1.87 MB
页数:15页
时间:2018-07-12
《ssh企业培训之spring组件装配》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、刘晓涛Spring组件装配集合装配自定义属性编辑器(日期处理)自动装配抽象配置本章目标集合装配publicclassCollectionInjectionService{privateStringstrValue;privateintintValue;privateListlistValue;privateString[]arrayValue;privateSetsetValue;privateMapmapValue;privateDatedateValue;//getXxx()与setXxx()方法}集合装配2、e="strValue"value="hellolxt008!!!">aaabbbxxxyyy数组与Li3、st配置方式一样。集合装配abccbabacMainApplic4、ationContextctx=newClassPathXmlApplicationContext("applicationContext.xml");CollectionInjectionServicecollectionInjectionService=(CollectionInjectionService)ctx.getBean("collectionInjectionService");System.out.println(collectionInjectionService.getStrValue());System.out5、.println(collectionInjectionService.getIntValue());System.out.println(collectionInjectionService.getListValue());System.out.println(collectionInjectionService.getArrayValue()[2]);System.out.println(collectionInjectionService.getSetValue());System.out.println(collectionI6、njectionService.getMapValue());自定义属性编辑器2009-03-25步骤:继承PropertyEditorSupport类,覆盖setAsText()。将属性编辑器注册到spring中。DateUtilPropertyEditorpublicclassDateUtilPropertyEditorextendsPropertyEditorSuppo7、rt{privateStringformat="yyyy-MM-dd";publicvoidsetAsText(Stringtext)throwsIllegalArgumentException{SimpleDateFormatsdf=newSimpleDateFormat(format);try{Dated=sdf.parse(text);this.setValue(d);}catch(ParseExceptione){e.printStackTrace();}}}自定义属性编辑器-注册到Spring8、
2、e="strValue"value="hellolxt008!!!">aaabbbxxxyyy数组与Li
3、st配置方式一样。集合装配abccbabacMainApplic
4、ationContextctx=newClassPathXmlApplicationContext("applicationContext.xml");CollectionInjectionServicecollectionInjectionService=(CollectionInjectionService)ctx.getBean("collectionInjectionService");System.out.println(collectionInjectionService.getStrValue());System.out
5、.println(collectionInjectionService.getIntValue());System.out.println(collectionInjectionService.getListValue());System.out.println(collectionInjectionService.getArrayValue()[2]);System.out.println(collectionInjectionService.getSetValue());System.out.println(collectionI
6、njectionService.getMapValue());自定义属性编辑器2009-03-25步骤:继承PropertyEditorSupport类,覆盖setAsText()。将属性编辑器注册到spring中。DateUtilPropertyEditorpublicclassDateUtilPropertyEditorextendsPropertyEditorSuppo
7、rt{privateStringformat="yyyy-MM-dd";publicvoidsetAsText(Stringtext)throwsIllegalArgumentException{SimpleDateFormatsdf=newSimpleDateFormat(format);try{Dated=sdf.parse(text);this.setValue(d);}catch(ParseExceptione){e.printStackTrace();}}}自定义属性编辑器-注册到Spring
8、
此文档下载收益归作者所有