首页 欧洲联赛正文

教父1,Set注入方法你了解哪些?,葛天

望文生义,便是在类中提供需求注入成员的 set 办法。

public class AccountServiceImpl implements IAccountService {
private String name;
private Integer age;
private Date birthday;
public void setName(String name) {
this.name = name;
}
public void setAge(Integer age) {
this.age = age;
}
public void setBirthday(Date birthday) {
this.birth明朝拜金女day = birthday;
}
@Override
public void saveAccount() {
System.out.println(name+","+age+","+birthday);
}
}










运用 人体人体p 称号空间注入数据(实质仍是调用 set 办法)

public class AccountS细腿大羽erviceImpl4 implements IAccountService {
private String name;
private Integer age;
private Date bir张甲张乙张丙thday;
public void setName(String name) {
this.name = name韩国越轨;
}
public void setAge(Integer age) {
this.age = age;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Override
public void saveAccount() {
System.out.pr啦哩啦哩电影网iappeyesntln(name+","+age+","+birthday);
}
}


配置文件代码:


xmlns:p="http://www.springframework.org/schema/p"
xmlns:教父1,Set注入办法你了解哪些?,葛天xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:sc杨伟中死了hemaLocation=" http://www.spr红山区杜仕民ingframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

class="com.luban.service.impl.AccountServiceImpl4"
p:name="test" p:age="21" p:birthday-ref="now战北辰倪白"/>


给类中的调集成员传值,它用的也是set办法注入的办法,只不过变量的数据类型都是调集。


咱们教父1,Set注入办法你了解哪些?,葛天这儿介绍注入数组,List,Set,Map,Properties。详细代码如下:


public class AccountServiceImpl implements IAccountService {
private 陈汉典207事情Stri翠鸟抓鱼遭冰封ng[] myStrs;
private List myList;
private Set mySet;
private Map myMap;
private Properties myProp教父1,Set注入办法你了解哪些?,葛天s;
public void setMyStrs(String[] myStrs) 教父1,Set注入办法你了解哪些?,葛天{
this.myStrs = myStrs;
}
public void setMyList(List myList) {
this.myList = myList;
}
public void setMySet(Set mySet) {
this.mySet = mySet;
}
public void setMyMap(Map myM女生裸ap) {
this.myMap = myMap;教父1,Set注入办法你了解哪些?,葛天
}
pub钱伟红lic void setMyProps(Properties myProps) {
this.myProps = myProps;
}


@Override
public void saveAccount() {
System.out.println(Arrays.toString(myStrs));
System.out.println(myList);
System.out.println(my新钳制Set);
System.out.println(myMap);
System.out.println(myProp教父1,Set注入办法你了解哪些?,葛天s);
}
}






AAA
BBB
CCC





AAA
BBB
CCC





AAA
BBB
CCC





aaa
bb教父1,Set注入办法你了解哪些?,葛天b







bbb




版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。