ImageVerifierCode 换一换
格式:DOCX , 页数:7 ,大小:17.73KB ,
资源ID:17012570      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/17012570.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(pringIoC详解下篇文档格式.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

pringIoC详解下篇文档格式.docx

1、applicationContext.xml); TelePhone t = ac.getBean(,TelePhone.class); t.show(); org.junit.Test publicvoid test5() ApplicationContext ac = new ClassPathXmlApplicationContext(bean对应的java类 TelePhone.java/* * 手机类,模拟构造器注入 * author haifeng * */publicclassTelePhone private String cpu; private String ram; pu

2、blicTelePhone() super(); publicTelePhone(String cpu, String ram) this.cpu = cpu; this.ram = ram; publicvoidshow() System.out.println( TelePhone cpu: + cpu + , ram: + ram + /* * 手机类,模拟构造器注入 * author haifeng * */publicclassTelePhone private String cpu; public TelePhone() super(); public TelePhone(Stri

3、ng cpu, String ram) this.cpu = cpu; publicvoid show() System.out.println( SET方式注入对象:注入的对象需要在beans中声明,使用ref进行注入- 声明puter -studentmodel.Studentpropertyname=namehaydn/propertyputerref= publicvoidtest6() Student stu = ac.getBean(,Student.class); stu.show();org.junit.Test publicvoid test6() ApplicationCo

4、ntext ac = new ClassPathXmlApplicationContext(bean的对应JAVA类,Student.java * student实体类,模拟注入类对象 */publicclassStudent private String name; private puter puter; private TelePhone phone; publicvoidsetName(String name) this.name = name; publicvoidsetputer(puter puter) this.puter = puter; publicvoidsetPhone

5、(TelePhone phone) this.phone = phone; System.out.println(学生XX: + name); puter.show(); phone.show();/* * student实体类,模拟注入类对象 * author haifeng * */publicclassStudent private String name; publicvoid setName(String name) this.name = name; publicvoid setputer(puter puter) this.puter = puter; publicvoid se

6、tPhone(TelePhone phone) this.phone = phone; publicvoid show() System.out.println(List set map propetries 注入- 注入集合 -messagebean.Message- 字符串注入null值,方式一:不写该配置,方式2:不写value,加个null标签 - null/age23- 注入list -friendslistvalue摩严白子画杀阡陌花千骨洛十一糖宝- 注入set -citiessetXX- 注入MAP -scoremapentrykey=语文98/entry数学99英语100/ma

7、p- 注入配置文件 -dbParamspropspropkey=urllocalhostusernamerootpassword123- 表达式注入,类似EL表达式用#bean对象名.属性标记, -#dbProps.password- spring标签注入 ,其他bean中使用ref调用,set Map Propties都可以,使用时需要加入命名空间-util:listid=someList/util:- 加载properties文件创建Properties对象,location=classpath:dbcp.properties location表示指定文件路径 classpath表示绝对路

8、径 -propertiesid=dbPropslocation=properties location表示指定文件路径 classpath表示绝对路径 -测试类JAVA代码: publicvoidtest7() Message msg = ac.getBean(,Message.class); msg.show();org.junit.Test publicvoid test7() ApplicationContext ac = new ClassPathXmlApplicationContext(bean的对应JAVA类,Message.java * 消息类,模拟各种类型对象注入 */pub

9、licclassMessage private String name; privateint age; private List friends; private Set cities; private Map score; private Properties dbParams; private String password; publicvoidsetAge(int age) this.age = age; publicvoidsetFriends(List friends) this.friends = friends; publicvoidsetCities(Set cities)

10、 this.cities = cities; publicvoidsetScore(Map score) this.score = score; publicvoidsetDbParams(Properties dbParams) this.dbParams = dbParams; publicvoidsetPassword(String password) this.password = password;Message name: + name + , age: + age +, friends+ friends.toString()+,cities: +cities.toString()

11、+,score:+score.toString()+ ,properties:+dbParams.toString()+password:+password+ /* * map的遍历 */publicvoidshowMap() SetEntry map = score.entrySet(); for(Entry keys = dbParams.keySet(); for(Object o : keys) System.out.println(dbParams.get(o);/* * 消息类,模拟各种类型对象注入 * author haifeng * */publicclassMessage p

12、rivate String name; publicvoid setAge(int age) this.age = age; publicvoid setFriends(List friends) this.friends = friends; publicvoid setCities(Set cities) this.cities = cities; publicvoid setScore(Map score) this.score = score; publicvoid setDbParams(Properties dbParams) this.dbParams = dbParams; p

13、ublicvoid setPassword(String password) this.password = password;+ friends.toString()+score.toString()+ /* * map的遍历 */publicvoid showMap() Set map) System.out.println(e.getKey()+e.getValue(); /* * protries的遍历 */publicvoid showProp() Set- 自动装配的bean的id需要和待注入的bean的属性name一致,注入的名字需要和set方法的名字一致(不含set,首字母小写) - byType和名字没关系,根据类型自动装配 - 但是byType的bean中有相同类型的bean出现则会出错,而且还要以单例模式声明要注入的bean -autowire=byName

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1