Spring - constructor-arg和property的使用示例
2017-02-28 10:28
351 查看
原创地址:http://racoguo.blog.51cto.com/2309068/1236379
1、说明
constructor-arg:通过构造函数注入。
property:通过setter对应的方法注入。
2、constructor-arg的使用示例
(1)、Model代码:
(2)、xml配置:
说明:
3、property的使用示例
(1)、Model代码:
(2)、xml配置:
4、Test
(1)、测试代码:
(2)、输出结果:
Student [id=1, name=student, dream=[soldier, scientist, pilot],
score={math=90, english=85}, graduation=false]
Teacher [id=1, name=teacher]
1、说明
constructor-arg:通过构造函数注入。
property:通过setter对应的方法注入。
2、constructor-arg的使用示例
(1)、Model代码:
<
constructor-arg
name
=
"id"
value
=
"1"
/>也可以改成<[code]constructor-arg
index
=
"0"
value
=
"1"
/>方式;boolean的值既可以用0/1填充,也可以用true/false填充。
3、property的使用示例
(1)、Model代码:
(1)、测试代码:
Student [id=1, name=student, dream=[soldier, scientist, pilot],
score={math=90, english=85}, graduation=false]
Teacher [id=1, name=teacher]
相关文章推荐
- Spring - constructor-arg和property的使用示例
- Spring - constructor-arg和property的使用示例
- [JAVA][Spring]Spring2 constructor-arg和property的使用示例
- Spring - constructor-arg和property的使用示例
- Spring - constructor-arg和property的使用示例
- Spring - constructor-arg和property的使用示例
- Spring - constructor-arg和property的使用示例
- spring - property和constructor-arg的使用
- spring - property和constructor-arg的使用
- spring 学习之 bean 的注入方式 property和constructor-arg的使用方式
- property和constructor-arg的使用
- spring配置constructor-arg就报错,property就通过
- spring - constructor-arg 的使用
- spring - constructor-arg 的使用
- Spring使用xml配置bean,主要是constructor-arg
- Spring - constructor-arg和property
- Spring : constructor-arg property 注入
- property和constructor-arg的使用
- spring - constructor-arg 的使用
- property和constructor-arg的使用