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 送给学长毕业祝福语简短