吕淼 1 month ago
parent 8bec667902
commit ecf14830ce

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />

@ -12,4 +12,10 @@
<property name="studentCount" value="45"/>
<property name="description" value="优秀班集体"/>
</bean>
<bean id="course" class="com.ssm.ioc.Course">
<property name="courseId" value="1"/>
<property name="courseName" value="Java程序设计"/>
<property name="credit" value="4.0"/>
<property name="teacher" value="李老师"/>
</bean>
</beans>

@ -0,0 +1,74 @@
package com.ssm.ioc;
public class Course {
private Integer courseId; // 课程ID
private String courseName; // 课程名称
private Double credit; // 学分
private String teacher; // 教师
public Integer getCourseId() {
return courseId;
}
public void setCourseId(Integer courseId) {
this.courseId = courseId;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public Double getCredit() {
return credit;
}
public void setCredit(Double credit) {
this.credit = credit;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
@Override
public String toString() {
return "Course{" +
"courseId=" + courseId +
", courseName='" + courseName + '\'' +
", credit=" + credit +
", teacher='" + teacher + '\'' +
'}';
}
public Course(Integer courseId, String courseName, Double credit, String teacher) {
this.courseId = courseId;
this.courseName = courseName;
this.credit = credit;
this.teacher = teacher;
}
public Course(String courseName, Double credit, String teacher) {
this.courseName = courseName;
this.credit = credit;
this.teacher = teacher;
}
public Course() {
}
public void printCourseInfo() {
System.out.println("========== 课程信息 ==========");
System.out.println("课程ID: " + courseId);
System.out.println("课程名称: " + courseName);
System.out.println("学分: " + credit);
System.out.println("授课教师: " + teacher);
}
}

@ -8,6 +8,9 @@ public class TestIoc {
//TIP 当文本光标位于高亮显示的文本处时按 <shortcut actionId="ShowIntentionActions"/>
// 查看 IntelliJ IDEA 建议如何修正。
ApplicationContext ac=new ClassPathXmlApplicationContext("bean-ioc.xml");
Course course = (Course) ac.getBean("course");
System.out.println(course.toString());
Class clazz = (Class) ac.getBean("class");
System.out.println(clazz.toString());}
System.out.println(clazz.toString());
}
}

Loading…
Cancel
Save