
spring中给属性赋值的三种方式
发布日期:2021-05-10 01:18:27
浏览次数:22
分类:精选文章
本文共 3085 字,大约阅读时间需要 10 分钟。
Spring IOC������������������������������
������������������������������������
���Spring������������������������������������������������������������������������������������������������������������������������������������������
������HelloWorld���
���������������������������������������������������������������������������package com.vow.spring;public class HelloWorld { private String name; private int age; private String sex; public HelloWorld(String name, int age, String sex) { super(); this.name = name; this.age = age; this.sex = sex; } public void printf() { System.out.println(name); System.out.println(age); System.out.println(sex); }}
������Springbeans.xml
���Spring������������������������������<constructor-arg>
��������������������������� ���������
value
���������������������������������������index
������������������������������������������������������type
������������������������������������������������������������������value
���������������
������Spring������
���������������������Spring������������������bean���������class Main { public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloworld"); helloWorld.printf(); }}
������ setters������������
���������������������������������������������������setters���������������������������������<property>
���������������������������
������HelloWorld���
������������������������������set���������public class HelloWorld { private String name; private int age; private String sex; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public void printf() { System.out.println(name); System.out.println(age); System.out.println(sex); }}
������Springconfig.xml
���������
name
������������������������value
���������������������������������
������P������������������������
���Spring3.0���������������P������������
���������������������������������������������
������Springconfig.xml
P������������������
- ������������������������������������
p:name="vow ${user}"
. - ������������������������������
p:value
���p:ref
��������������������������������� - ���������������������������
scope
���������
������������
- ������������������������������������������������������������������
- setters���������������������������������������������������������������
- P���������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
表示我来过!
[***.240.166.169]2025年04月11日 07时02分18秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
解决Nginx 404 not found问题
2021-05-12
Lumen 表单校验配置 validation 的中文 (多语言) 错误语
2021-05-12
计算机网络之第三章笔记--数据链路层
2021-05-12
计算机网络之第六章学习笔记--应用层
2021-05-12
Java项目之数据与表格的导出导入操作
2021-05-12
创建型模式之简单工厂模式实例及代码操作
2021-05-12
XML简单入门(2019.8.13)
2021-05-12
广东外语外贸大学第三届网络安全大赛Writeup
2021-05-12
HDU - 1576(A/B)
2021-05-12
自学Java网站推荐
2021-05-12
跟着燕青学分布式事务控制技术方案
2021-05-12
燕青Apollo视频教程分享
2021-05-12
跟燕青学Apollo分布式配置中心-Apollo快速入门
2021-05-12
Nacos视频教程分享
2021-05-12
Activiti视频分享
2021-05-12
VS2019 报错: LINK Error 无法找到 MSCOREE.lib的解决办法
2021-05-12
MYSQL数据库的优化
2021-05-12
关于JS中的内存溢出与内存泄漏
2021-05-12
Vue——v-model结合值绑定写法
2021-05-12
JS实现防抖与节流(使用按钮触发事件)
2021-05-12