5.1 编写一个Demo3的实体类;
package com.eduask.entity;
public class Demo3 {
private int id;
private String name;
private String pwd;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public Demo3(){
System.out.println("这是Demo3的构造方法");
}
public void testDemo3(){
System.out.println("Demo3 [id=" + id + ", name=" + name + ", pwd=" + pwd + "]");
}
}
5.2编写一个TestDemo3测试类;
package com.eduask.entity;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDemo3 {
public static void main(String[] args) {
ClassPathXmlApplicationContext cx = new ClassPathXmlApplicationContext("demo3.xml");
Demo3 demo3 = (Demo3) cx.getBean("Demo3");
demo3.testDemo3();
}
}
5.3 编写一个demo3.xml的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"
>
<bean id="Demo3" class="com.eduask.entity.Demo3" scope="prototype">
<property name="id" value="001"/>
<property name="name" value="tom"/>
<property name="pwd" value="123456"/>
</bean>
</beans>
spring中实体类值的设定
原创wx62e9cee37942d 博主文章分类:Spring ©著作权
文章标签 spring中实体类值的设定 spring值的设定 xml spring 实体类 文章分类 后端开发
©著作权归作者所有:来自51CTO博客作者wx62e9cee37942d的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:set注入和构造方法注入
下一篇:init和destory方法
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java使用JsonNode判断实体类非空
使用jsonNode去判断实体类的参数是否为空
jsonnode java hutool -
java将map中的值放到对象中
java将map中的值放到对象中
Java if语句 java