Spring注入值到Bean的三种方式
在Spring中,有三种方式注入值到bean属性。
正常的方式
快捷方式
“p”模式
新建一个User类,它包含username和password两个属性,现在使用spring的IOC注入值到该bean。
packagecom.example.pojo;
publicclassUser
{
privateStringusername;
privateStringpassword;
publicStringgetUsername(){
returnusername;
}
publicvoidsetUsername(Stringusername){
this.username=username;
}
publicStringgetPassword(){
returntype;
}
publicvoidsetPassword(Stringpassword){
this.password=password;
}
}
1.正常方式
在一个“value”标签注入值,并附有“property”标签结束。
scott tiger
2.快捷方式
注入值“value”属性。
3.“p”模式
通过使用“p”模式作为注入值到一个属性。
记住声明xmlns:p=”http://www.springframework.org/schema/p"在SpringXMLbean配置文件。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短