创建TestIoc.java和bean-ioc.xml,创建User.java实现了用户管理

main
李根 1 week ago
parent 9f5f140c36
commit 9b9131930e

@ -0,0 +1,13 @@
<?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="user" class="com.ssm.ioc.User">
<property name="userId" value="1001"/>
<property name="username" value="lisi"/>
<property name="userpass" value="123456"/>
<property name="truename" value="李四"/>
<property name="phone" value="13800138000"/>
<property name="registerTime" value="2025-04-08 10:00:00"/>
</bean>
</beans>

@ -0,0 +1,17 @@
package com.ssm.ioc;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestIoc {
// 标准Java程序入口方法严格遵循语法
public static void main(String[] args) {
// 1. 加载Spring配置文件初始化IoC容器
ApplicationContext context = new ClassPathXmlApplicationContext("bean-ioc.xml");
// 2. 获取并打印用户信息
User user = context.getBean("user", User.class);
System.out.println("===== 用户管理模块 =====");
System.out.println(user);
}
}

@ -0,0 +1,42 @@
package com.ssm.ioc;
public class User {
private Integer userId;
private String username;
private String userpass;
private String truename;
private String phone;
private String registerTime;
public User() {}
public Integer getUserId() { return userId; }
public void setUserId(Integer userId) { this.userId = userId; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getUserpass() { return userpass; }
public void setUserpass(String userpass) { this.userpass = userpass; }
public String getTruename() { return truename; }
public void setTruename(String truename) { this.truename = truename; }
public String getPhone() { return phone; }
public void setPhone(String phone) { this.phone = phone; }
public String getRegisterTime() { return registerTime; }
public void setRegisterTime(String registerTime) { this.registerTime = registerTime; }
@Override
public String toString() {
return "User{" +
"userId=" + userId +
", username='" + username + '\'' +
", userpass='" + userpass + '\'' +
", truename='" + truename + '\'' +
", phone='" + phone + '\'' +
", registerTime='" + registerTime + '\'' +
'}';
}
}
Loading…
Cancel
Save