constructor-arg的使用以及Properties的使用
来源:互联网 发布:竹村桐子知乎 编辑:程序博客网 时间:2024/06/03 20:12
- constructor-arg的使用:通过构造函数注入
- public class Man {
- private String name ;
- private int age;
- private List hobby;
- private Map friends;
- private Set set;
- private boolean ifMarried;
- public Man() {
- }
- public Man(String name, int age,List hobby,Map friends,Set set,boolean ifMarried){
- this.name = name;
- this.age = age;
- this.hobby = hobby;
- this.friends = friends;
- this.set = set;
- this.ifMarried = ifMarried;
- }
- public String getInfo(){
- String info = "姓名:"+this.name+"\n年龄:"+this.age+"\n爱好:"+this.hobby+"\n朋友:"+this.friends+"\n婚否:"+this.ifMarried+"\n其他的:"+this.set;
- return info;
- }
- 然后进行XML的配置:
- <bean id="man" class="com.spring.test.man.Man">
- <constructor-arg value="zzy" index="0" >
- </constructor-arg>
- <constructor-arg value="10" index="1">
- </constructor-arg>
- <constructor-arg>
- <list>
- <value>movie</value>
- <value>music</value>
- </list>
- </constructor-arg>
- <constructor-arg>
- <set>
- <value>Lady is GaGa</value>
- <value>GaGa is Lady</value>
- </set>
- </constructor-arg>
- <constructor-arg>
- <map>
- <entry key="liuhua" value="man"></entry>
- <entry key="xujinglei" value="female"></entry>
- </map>
- </constructor-arg>
- <constructor-arg index="5" value="0">
- </constructor-arg>
- </bean>
- Properties的使用:通过setter方法注入
- java代码:
- public class Doctor {
- private String name;
- private String sex;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSex() {
- return sex;
- }
- public void setSex(String sex) {
- this.sex = sex;
- }
- public void init(){
- System.out.println("88888888888");
- }
- public void init(String name,String sex){
- this.name = name;
- this.sex = sex;
- }
- }
- 相应的XML文件:
- <bean id="doctor" class="com.spring.test.man.Doctor" init-method="init">
- <property name="name" value="doctor"></property>
- <property name="sex" value="i don't know"></property>
- /bean>
0 0
- constructor-arg的使用以及Properties的使用
- spring - constructor-arg 的使用
- spring - constructor-arg 的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- spring - property和constructor-arg的使用
- property和constructor-arg的使用
- spring - property和constructor-arg的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- property和constructor-arg的使用
- constructor-arg和 property的使用
- Spring - constructor-arg和property的使用示例
- java反射机制
- 【MVC5】6.从控制器访问您的模型的数据
- <stdlib.h>包括的函数讲解 (
- DNS解析过程详解
- vs2010字体和颜色的舒适设置
- constructor-arg的使用以及Properties的使用
- Linux安全体系的文件权限管理
- rand_mode使用注意
- 在SpringMVC中获取request对象的几种方式
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C 数学
- 用JAVA后台判断一个URL是否有效
- SubClassWindow用法
- Android资源混淆工具使用说明
- Spark on yarn的内存分配问题