新建bean
创建set方法
jpackage com.dependency.spring6.bean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class User {
private static final Logger LOGGER = LoggerFactory.getLogger(User.class);
private String username;
private String password;
private int age;
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setAge(int age) {
this.age = age;
}
public void inster(){
LOGGER.info("获取成员信息");
}
@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
", age=" + age +
'}';
}
}
xml里面进行数据填入
<bean id="userBean" class="com.dependency.spring6.bean.User">
<!--重点:如果是简单类型赋值,就不能使用ref了,就需要使用value-->
<property name="username" value="张三"/>
<property name="password" value="beanclass"/>
<property name="age" value="20"/>
</bean>
在test里面进行测试
运行结果
这些都为简单类型
在实际开发中,我们一般不会把Date当做简单类型,虽然它是简单类型。一般会采用ref给Date类型的属性赋值