feat(spring): 更新Spring配置文件并完善依赖注入功能

- 修改bean-di.xml配置文件,更新Student Bean的配置信息
- 将Student实体类的学号从2026001更改为2025001
- 添加完整的Department院系管理Bean配置,包括院系ID、名称、编号等属性
- 删除注释的专业Bean配置示例代码
- 在TestDi测试类中添加Student Bean的获取和打印功能
- 完善控制台输出和信息展示逻辑
main
CesarH 1 day ago
parent 1029033397
commit d8306e8184

@ -2,16 +2,34 @@
<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">
<!-- 配置Student实体类的Bean采用Setter方法注入 -->
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="student" class="com.ssm.di.Student">
<!-- 依赖注入属性值,根据实际需求修改属性值 -->
<property name="studentId" value="2026001"/>
<property name="studentName" value="张三"/>
<property name="className" value="计科2班"/>
<property name="major" value="计算机科学与技术"/>
<property name="age" value="20"/>
<property name="phone" value="13800138000"/>
<property name="studentId" value="2025001"/>
<property name="studentName" value="张三"/>
<property name="className" value="计科2班"/>
<property name="major" value="计算机科学与技术"/>
<property name="age" value="20"/>
<property name="phone" value="13800138000"/>
</bean>
<!-- ==================== 1. 院系管理Bean配置setter方式注入 ==================== -->
<bean id="department" class="com.ssm.ioc.Department">
<!-- 院系ID -->
<property name="deptId" value="1"/>
<!-- 院系名称 -->
<property name="deptName" value="计算机学院"/>
<!-- 院系编号 -->
<property name="deptNo" value="CS001"/>
<!-- 院系负责人 -->
<property name="deptManager" value="张教授"/>
<!-- 联系电话 -->
<property name="deptPhone" value="010-12345678"/>
<!-- 所属校区 -->
<property name="campus" value="主校区"/>
</bean>
</beans>
</beans>

@ -3,6 +3,17 @@
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="student" class="com.ssm.di.Student">
<property name="studentId" value="2025001"/>
<property name="studentName" value="张三"/>
<property name="className" value="计科2班"/>
<property name="major" value="计算机科学与技术"/>
<property name="age" value="20"/>
<property name="phone" value="13800138000"/>
</bean>
<!-- ==================== 1. 院系管理Bean配置setter方式注入 ==================== -->
<bean id="department" class="com.ssm.ioc.Department">
@ -20,15 +31,5 @@
<property name="campus" value="主校区"/>
</bean>
<!-- ==================== 其他小组实体Bean可在此处继续配置如学生、专业、班级等 ==================== -->
<!-- 示例专业Bean与院系关联ref引用department -->
<!--
<bean id="major" class="com.ssm.di.xml.Major">
<property name="majorId" value="1"/>
<property name="majorName" value="计算机科学与技术"/>
<property name="majorCode" value="CS001"/>
<property name="department" ref="department"/>
</bean>
-->
</beans>

@ -8,6 +8,11 @@ public class TestDi {
public static void main(String[] args) {
// 1. 初始化Spring容器加载配置文件
ApplicationContext context = new ClassPathXmlApplicationContext("bean-di.xml");
Student student = context.getBean("student", Student.class);
System.out.println(student);
student.printInfo();
// ==================== 2. 院系管理测试 ====================
// 获取Department实例

@ -2,22 +2,18 @@
<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
<<<<<<< HEAD
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 配置Student实体类的Bean采用Setter方法注入 -->
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="student" class="com.ssm.di.Student">
<!-- 依赖注入属性值,根据实际需求修改属性值 -->
<property name="studentId" value="2026001"/>
<property name="studentName" value="张三"/>
<property name="className" value="计科2班"/>
<property name="major" value="计算机科学与技术"/>
<property name="age" value="20"/>
<property name="phone" value="13800138000"/>
<property name="studentId" value="2025001"/>
<property name="studentName" value="张三"/>
<property name="className" value="计科2班"/>
<property name="major" value="计算机科学与技术"/>
<property name="age" value="20"/>
<property name="phone" value="13800138000"/>
</bean>
</beans>
=======
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- ==================== 1. 院系管理Bean配置setter方式注入 ==================== -->
<bean id="department" class="com.ssm.ioc.Department">
@ -35,16 +31,5 @@
<property name="campus" value="主校区"/>
</bean>
<!-- ==================== 其他小组实体Bean可在此处继续配置如学生、专业、班级等 ==================== -->
<!-- 示例专业Bean与院系关联ref引用department -->
<!--
<bean id="major" class="com.ssm.di.xml.Major">
<property name="majorId" value="1"/>
<property name="majorName" value="计算机科学与技术"/>
<property name="majorCode" value="CS001"/>
<property name="department" ref="department"/>
</bean>
-->
</beans>
>>>>>>> origin/main

Loading…
Cancel
Save