任务三
main
董倩 3 weeks ago
parent e64cbbf01c
commit 972bf2f50e

@ -11,11 +11,10 @@
<property name="studentCount" value="45"/>
</bean>
<!-- 分工2课程Bean Setter属性注入 -->
<bean id="course" class="com.ssm.di.xml.Course">
<property name="courseId" value="1001"/>
<property name="courseName" value="JavaSSM框架开发"/>
<property name="credit" value="4"/>
<bean id="score" class="com.ssm.di.xml.Score">
<property name="scoreId" value="001"/>
<property name="studentId" value="2025001"/>
<property name="score" value="95.5"/>
</bean>
</beans>

@ -0,0 +1,35 @@
package com.ssm.di.xml;
// 成绩实体类 DI XML版
public class Score {
private Integer scoreId;
private Integer studentId;
private Double score;
public Score() {}
public Integer getScoreId() { return scoreId; }
public void setScoreId(Integer scoreId) { this.scoreId = scoreId; }
public Integer getStudentId() { return studentId; }
public void setStudentId(Integer studentId) { this.studentId = studentId; }
public Double getScore() { return score; }
public void setScore(Double score) { this.score = score; }
// 重写toString
@Override
public String toString() {
return "Score{" +
"成绩ID=" + scoreId +
", 学生学号=" + studentId +
", 考试分数=" + score +
'}';
}
// printInfo方法
public void printInfo() {
System.out.println("\n===== 成绩信息 =====");
System.out.println("成绩ID" + scoreId);
System.out.println("学生学号:" + studentId);
System.out.println("考试分数:" + score);
}
}

@ -11,19 +11,20 @@ public class TestDI {
// 获取4个分工Bean对象
Class classInfo = (Class) ac.getBean("classInfo");
Course course = (Course) ac.getBean("course");
Score score = (Score) ac.getBean("score");
System.out.println("========== 调用printInfo()方法输出 ==========");
// 任务要求调用printInfo方法输出每个实体属性
classInfo.printInfo();
course.printInfo();
score.printInfo();
System.out.println("\n========== 重写toString()方法输出 ==========");
// 任务要求调用toString方法输出
System.out.println(classInfo);
System.out.println(course);
System.out.println(score);
}
}

@ -11,11 +11,10 @@
<property name="studentCount" value="45"/>
</bean>
<!-- 分工2课程Bean Setter属性注入 -->
<bean id="course" class="com.ssm.di.xml.Course">
<property name="courseId" value="1001"/>
<property name="courseName" value="JavaSSM框架开发"/>
<property name="credit" value="4"/>
<bean id="score" class="com.ssm.di.xml.Score">
<property name="scoreId" value="001"/>
<property name="studentId" value="2025001"/>
<property name="score" value="95.5"/>
</bean>
</beans>
Loading…
Cancel
Save