配置文件需要导入的配置
| xmlns:p="http://www.springframework.org/schema/p" |
| xmlns:c="http://www.springframework.org/schema/c" |
创建实体类
| public class user { |
| private String name; |
| private int age; |
| |
| public user(String name, int age) { |
| this.name = name; |
| this.age = age; |
| } |
| |
| public user() { |
| } |
| |
| 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; |
| } |
| |
| @Override |
| public String toString() { |
| return "user{" + |
| "name='" + name + '\'' + |
| ", age=" + age + |
| '}'; |
| } |
| } |
配置文件
| |
| <bean id="user" class="com.Google.pojo.user" p:age="19" p:name="Spring"/> |
| |
| |
| <bean id="user1" class="com.Google.pojo.user" c:age="20" c:name="Spring1"/> |
实现
| @Test |
| public void test(){ |
| ApplicationContext context = new ClassPathXmlApplicationContext("userBeans.xml"); |
| user user = context.getBean("user", user.class); |
| System.out.println(user); |
| } |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术