代宇航用户管理并推送

王健旭材料管理
喻廷屿材料出入库管理
孙佳兴预约管理并测试
赵文博实验室管理
main
your-name 2 weeks ago
parent 34803158ac
commit 87b86bdccc

@ -10,5 +10,9 @@
<orderEntry type="library" name="commons-logging-1.1.1" level="project" />
<orderEntry type="library" name="libs" level="project" />
<orderEntry type="library" name="spring-aop-5.1.6.RELEASE" level="project" />
<orderEntry type="library" name="aspectj.weaver-1.6.8.RELEASE(2)" level="project" />
<orderEntry type="library" name="aspectjweaver-1.9.7" level="project" />
<orderEntry type="library" name="jsp-api" level="project" />
<orderEntry type="library" name="spring-web-5.1.6.RELEASE" level="project" />
</component>
</module>

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 1. 配置所有实体类Bean -->
<bean id="user" class="com.ssm.aop.xml.User">
<property name="username" value="daiyuhang"/>
<property name="userpass" value="123456"/>
<property name="truename" value="代宇航"/>
<property name="age" value="20"/>
<property name="role" value="管理员"/>
</bean>
<bean id="material" class="com.ssm.aop.xml.Material">
<property name="materialId" value="M001"/>
<property name="materialName" value="试管"/>
<property name="type" value="玻璃耗材"/>
<property name="stock" value="100"/>
<property name="unit" value="个"/>
</bean>
<bean id="nowDate" class="java.util.Date"/>
<bean id="startDate" class="java.util.Date"/>
<bean id="endDate" class="java.util.Date"/>
<bean id="materialRecord" class="com.ssm.aop.xml.MaterialRecord">
<property name="recordId" value="R001"/>
<property name="materialId" value="M001"/>
<property name="operator" value="喻廷屿"/>
<property name="nums" value="20"/>
<property name="operateDate" ref="nowDate"/>
<property name="type" value="入库"/>
</bean>
<bean id="appointment" class="com.ssm.aop.xml.Appointment">
<property name="appointmentId" value="A001"/>
<property name="username" value="孙佳兴"/>
<property name="labId" value="L001"/>
<property name="startTime" ref="startDate"/>
<property name="endTime" ref="endDate"/>
<property name="purpose" value="化学实验"/>
</bean>
<bean id="laboratory" class="com.ssm.aop.xml.Laboratory">
<property name="labId" value="L001"/>
<property name="labName" value="化学实验室1号"/>
<property name="location" value="实验楼3楼"/>
<property name="capacity" value="30"/>
<property name="status" value="空闲"/>
</bean>
<!-- 2. 配置日志通知类Bean -->
<bean id="log" class="com.ssm.aop.xml.Log"/>
<!-- 3. AOP配置切面、切入点、前置通知 -->
<aop:config>
<!-- 定义切面,切面=通知类+切入点 -->
<aop:aspect ref="log">
<!-- 定义切入点匹配com.ssm.aop.xml包下所有类的printInfo()方法 -->
<aop:pointcut id="printInfoPointcut" expression="execution(* com.ssm.aop.xml.*.printInfo(..))"/>
<!-- 前置通知在切入点方法执行前调用beforeLog方法 -->
<aop:before method="beforeLog" pointcut-ref="printInfoPointcut"/>
</aop:aspect>
</aop:config>
</beans>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.ssm.di.annotation"/>
</beans>

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="teacher" class="com.ssm.aop.xml.Teacher">
<property name="teacherId" value="T001"/>
<property name="name" value="张教授"/>
<property name="title" value="教授"/>
</bean>
<bean id="course" class="com.ssm.aop.xml.Course">
<property name="courseId" value="C001"/>
<property name="courseName" value="Java程序设计"/>
<property name="credit" value="4"/>
<property name="teacher" ref="teacher"/>
</bean>
<bean id="logAdvice" class="com.ssm.aop.xml.Log"/>
<aop:config>
<aop:aspect ref="logAdvice">
<aop:pointcut id="printInfoPointcut"
expression="execution(* com.ssm.aop.xml.Course.printInfo(..))"/>
<aop:before method="beforeAdvice" pointcut-ref="printInfoPointcut"/>
</aop:aspect>
</aop:config>
</beans>

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 开启组件扫描Spring会自动扫描@注解 -->
<context:component-scan base-package="com.ssm.di.annotation"/>
<!-- 给Teacher属性赋值 -->
<bean id="teacher" class="com.ssm.di.annotation.Teacher">
<property name="teacherId" value="T001"/>
<property name="name" value="张教授"/>
<property name="title" value="教授"/>
</bean>
<!-- 给Course属性赋值teacher已经由@Autowired自动注入 -->
<bean id="course" class="com.ssm.di.annotation.Course">
<property name="courseId" value="C001"/>
<property name="courseName" value="Java程序设计"/>
<property name="credit" value="4"/>
</bean>
</beans>

@ -1,22 +1,60 @@
<?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
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Teacher Bean注入工号、姓名、职称 -->
<bean id="teacher" class="com.ssm.di.xml.Teacher">
<property name="teacherId" value="T001"/>
<property name="name" value="张教授"/>
<property name="title" value="教授"/>
<!-- 1. 用户管理模块 - User Beansetter注入 -->
<bean id="user" class="com.ssm.di.User">
<property name="username" value="daiyuhang"/>
<property name="userpass" value="123456"/>
<property name="truename" value="代宇航"/>
<property name="age" value="20"/>
<property name="role" value="管理员"/>
</bean>
<!-- Course Bean注入课程编号、名称、学分和Teacher对象 -->
<bean id="course" class="com.ssm.di.xml.Course">
<property name="courseId" value="C001"/>
<property name="courseName" value="Java程序设计"/>
<property name="credit" value="4"/>
<property name="teacher" ref="teacher"/>
<!-- 2. 材料管理模块 - Material Beansetter注入 -->
<bean id="material" class="com.ssm.di.Material">
<property name="materialId" value="M001"/>
<property name="materialName" value="试管"/>
<property name="type" value="玻璃耗材"/>
<property name="stock" value="100"/>
<property name="unit" value="个"/>
</bean>
<!-- 用于注入日期的工具Bean -->
<bean id="nowDate" class="java.util.Date"/>
<bean id="startDate" class="java.util.Date"/>
<bean id="endDate" class="java.util.Date"/>
<!-- 3. 材料出入库管理模块 - MaterialRecord Beansetter注入 -->
<bean id="materialRecord" class="com.ssm.di.MaterialRecord">
<property name="recordId" value="R001"/>
<property name="materialId" value="M001"/>
<property name="operator" value="喻廷屿"/>
<property name="nums" value="20"/>
<property name="operateDate" ref="nowDate"/>
<property name="type" value="入库"/>
</bean>
<!-- 4. 预约管理模块 - Appointment Beansetter注入 -->
<bean id="appointment" class="com.ssm.di.Appointment">
<property name="appointmentId" value="A001"/>
<property name="username" value="孙佳兴"/>
<property name="labId" value="L001"/>
<property name="startTime" ref="startDate"/>
<property name="endTime" ref="endDate"/>
<property name="purpose" value="化学实验"/>
</bean>
<!-- 5. 实验室管理模块 - Laboratory Beansetter注入 -->
<bean id="laboratory" class="com.ssm.di.Laboratory">
<property name="labId" value="L001"/>
<property name="labName" value="化学实验室1号"/>
<property name="location" value="实验楼3楼"/>
<property name="capacity" value="30"/>
<property name="status" value="空闲"/>
</bean>
</beans>

@ -1,9 +0,0 @@
<?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">
<!-- 这里是 Spring 配置,不是界面布局 -->
</beans>

@ -1,45 +1,58 @@
<?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
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 用户Bean -->
<!-- 用户 -->
<bean id="user" class="com.ssm.ioc.User">
<property name="username" value="zhangsan"/>
<property name="username" value="daiyuhang"/>
<property name="userpass" value="123456"/>
<property name="truename" value="张三"/>
<property name="age" value="22"/>
<property name="email" value="zhangsan@qq.com"/>
<property name="truename" value="代宇航"/>
<property name="age" value="20"/>
<property name="role" value="管理员"/>
</bean>
<!-- 订单Bean -->
<bean id="order" class="com.ssm.ioc.Order">
<property name="id" value="ORDER2025001"/>
<property name="username" value="zhangsan"/>
<property name="goodsname" value="笔记本电脑"/>
<property name="nums" value="1"/>
<property name="date">
<bean class="java.util.Date"/>
</property>
<!-- 材料 -->
<bean id="material" class="com.ssm.ioc.Material">
<property name="materialId" value="M001"/>
<property name="materialName" value="试管"/>
<property name="type" value="玻璃耗材"/>
<property name="stock" value="100"/>
<property name="unit" value="个"/>
</bean>
<!-- 商品Bean -->
<bean id="goods" class="com.ssm.ioc.Goods">
<property name="goodsId" value="G001"/>
<property name="goodsName" value="MateBook"/>
<property name="price" value="5999"/>
<property name="brand" value="华为"/>
<property name="stock" value="100"/>
<!-- 材料记录 -->
<bean id="materialRecord" class="com.ssm.ioc.MaterialRecord">
<property name="recordId" value="R001"/>
<property name="materialId" value="M001"/>
<property name="operator" value="喻廷屿"/>
<property name="nums" value="20"/>
<property name="operateDate" ref="nowDate"/>
<property name="type" value="入库"/>
</bean>
<bean id="nowDate" class="java.util.Date"/>
<!-- 预约 -->
<bean id="appointment" class="com.ssm.ioc.Appointment">
<property name="appointmentId" value="A001"/>
<property name="username" value="孙佳兴"/>
<property name="labId" value="L001"/>
<property name="startTime" ref="startDate"/>
<property name="endTime" ref="endDate"/>
<property name="purpose" value="化学实验"/>
</bean>
<bean id="startDate" class="java.util.Date"/>
<bean id="endDate" class="java.util.Date"/>
<!-- 教师Bean -->
<bean id="teacher" class="com.ssm.ioc.Teacher">
<property name="teacherId" value="T001"/>
<property name="name" value="王老师"/>
<property name="course" value="Java编程"/>
<property name="department" value="计算机学院"/>
<property name="workAge" value="10"/>
<!-- 实验室 -->
<bean id="laboratory" class="com.ssm.ioc.Laboratory">
<property name="labId" value="L001"/>
<property name="labName" value="化学实验室1号"/>
<property name="location" value="实验楼3楼"/>
<property name="capacity" value="30"/>
<property name="status" value="空闲"/>
</bean>
</beans>

@ -0,0 +1,37 @@
package com.ssm.aop.xml;
import java.util.Date;
public class Appointment {
private String appointmentId;
private String username;
private String labId;
private Date startTime;
private Date endTime;
private String purpose;
public Appointment() {}
public String getAppointmentId() { return appointmentId; }
public void setAppointmentId(String appointmentId) { this.appointmentId = appointmentId; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public Date getStartTime() { return startTime; }
public void setStartTime(Date startTime) { this.startTime = startTime; }
public Date getEndTime() { return endTime; }
public void setEndTime(Date endTime) { this.endTime = endTime; }
public String getPurpose() { return purpose; }
public void setPurpose(String purpose) { this.purpose = purpose; }
public void printInfo() {
System.out.println("预约信息:");
System.out.println("预约编号:" + appointmentId);
System.out.println("预约人:" + username);
System.out.println("实验室编号:" + labId);
System.out.println("开始时间:" + startTime);
System.out.println("结束时间:" + endTime);
System.out.println("用途:" + purpose);
}
}

@ -1,20 +0,0 @@
package com.ssm.aop.xml;
public class Course {
private String courseId;
private String courseName;
private int credit;
private Teacher teacher;
public void setCourseId(String courseId) { this.courseId = courseId; }
public void setCourseName(String courseName) { this.courseName = courseName; }
public void setCredit(int credit) { this.credit = credit; }
public void setTeacher(Teacher teacher) { this.teacher = teacher; }
public void printInfo() {
System.out.println("课程编号:" + courseId);
System.out.println("课程名称:" + courseName);
System.out.println("学分:" + credit);
System.out.println("授课教师信息:工号:" + teacher.getTeacherId() + ",姓名:" + teacher.getName() + ",职称:" + teacher.getTitle());
}
}

@ -0,0 +1,31 @@
package com.ssm.aop.xml;
public class Laboratory {
private String labId;
private String labName;
private String location;
private int capacity;
private String status;
public Laboratory() {}
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public String getLabName() { return labName; }
public void setLabName(String labName) { this.labName = labName; }
public String getLocation() { return location; }
public void setLocation(String location) { this.location = location; }
public int getCapacity() { return capacity; }
public void setCapacity(int capacity) { this.capacity = capacity; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public void printInfo() {
System.out.println("实验室信息:");
System.out.println("实验室编号:" + labId);
System.out.println("实验室名称:" + labName);
System.out.println("位置:" + location);
System.out.println("容纳人数:" + capacity);
System.out.println("状态:" + status);
}
}

@ -3,9 +3,8 @@ package com.ssm.aop.xml;
import org.aspectj.lang.JoinPoint;
public class Log {
public void beforeAdvice(JoinPoint joinPoint) {
String className = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
System.out.println("前置通知:模拟日志的记录...目标类是:" + className + ",被切入通知的目标方法为:" + methodName);
// 前置通知在printInfo方法执行前输出日志
public void beforeLog(JoinPoint joinPoint) {
System.out.println("【前置通知】模拟日志记录...目标类是:" + joinPoint.getTarget() + ",被切入通知的目标方法为:" + joinPoint.getSignature().getName());
}
}

@ -0,0 +1,31 @@
package com.ssm.aop.xml;
public class Material {
private String materialId;
private String materialName;
private String type;
private int stock;
private String unit;
public Material() {}
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getMaterialName() { return materialName; }
public void setMaterialName(String materialName) { this.materialName = materialName; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public int getStock() { return stock; }
public void setStock(int stock) { this.stock = stock; }
public String getUnit() { return unit; }
public void setUnit(String unit) { this.unit = unit; }
public void printInfo() {
System.out.println("材料信息:");
System.out.println("材料编号:" + materialId);
System.out.println("材料名称:" + materialName);
System.out.println("类型:" + type);
System.out.println("库存:" + stock);
System.out.println("单位:" + unit);
}
}

@ -0,0 +1,37 @@
package com.ssm.aop.xml;
import java.util.Date;
public class MaterialRecord {
private String recordId;
private String materialId;
private String operator;
private int nums;
private Date operateDate;
private String type;
public MaterialRecord() {}
public String getRecordId() { return recordId; }
public void setRecordId(String recordId) { this.recordId = recordId; }
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getOperator() { return operator; }
public void setOperator(String operator) { this.operator = operator; }
public int getNums() { return nums; }
public void setNums(int nums) { this.nums = nums; }
public Date getOperateDate() { return operateDate; }
public void setOperateDate(Date operateDate) { this.operateDate = operateDate; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public void printInfo() {
System.out.println("材料出入库记录:");
System.out.println("记录编号:" + recordId);
System.out.println("材料编号:" + materialId);
System.out.println("操作人:" + operator);
System.out.println("操作数量:" + nums);
System.out.println("操作日期:" + operateDate);
System.out.println("操作类型:" + type);
}
}

@ -1,15 +0,0 @@
package com.ssm.aop.xml;
public class Teacher {
private String teacherId;
private String name;
private String title;
public void setTeacherId(String teacherId) { this.teacherId = teacherId; }
public void setName(String name) { this.name = name; }
public void setTitle(String title) { this.title = title; }
public String getTeacherId() { return teacherId; }
public String getName() { return name; }
public String getTitle() { return title; }
}

@ -5,8 +5,27 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestAopXml {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("bean-aop-xml.xml");
Course course = context.getBean("course", Course.class);
course.printInfo();
// 【唯一正确写法】从类路径加载配置文件
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-aop.xml");
System.out.println("===== 用户管理模块 =====");
User user = (User) context.getBean("user");
user.printInfo();
System.out.println("\n===== 材料管理模块 =====");
Material material = (Material) context.getBean("material");
material.printInfo();
System.out.println("\n===== 材料出入库管理模块 =====");
MaterialRecord record = (MaterialRecord) context.getBean("materialRecord");
record.printInfo();
System.out.println("\n===== 预约管理模块 =====");
Appointment appointment = (Appointment) context.getBean("appointment");
appointment.printInfo();
System.out.println("\n===== 实验室管理模块 =====");
Laboratory lab = (Laboratory) context.getBean("laboratory");
lab.printInfo();
}
}

@ -0,0 +1,31 @@
package com.ssm.aop.xml;
public class User {
private String username;
private String userpass;
private String truename;
private int age;
private String role;
public User() {}
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 int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getRole() { return role; }
public void setRole(String role) { this.role = role; }
public void printInfo() {
System.out.println("用户信息:");
System.out.println("用户名:" + username);
System.out.println("密码:" + userpass);
System.out.println("真实姓名:" + truename);
System.out.println("年龄:" + age);
System.out.println("角色:" + role);
}
}

@ -0,0 +1,37 @@
package com.ssm.di;
import java.util.Date;
public class Appointment {
private String appointmentId;
private String username;
private String labId;
private Date startTime;
private Date endTime;
private String purpose;
public Appointment() {}
public String getAppointmentId() { return appointmentId; }
public void setAppointmentId(String appointmentId) { this.appointmentId = appointmentId; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public Date getStartTime() { return startTime; }
public void setStartTime(Date startTime) { this.startTime = startTime; }
public Date getEndTime() { return endTime; }
public void setEndTime(Date endTime) { this.endTime = endTime; }
public String getPurpose() { return purpose; }
public void setPurpose(String purpose) { this.purpose = purpose; }
public void printInfo() {
System.out.println("预约信息:");
System.out.println("预约编号:" + appointmentId);
System.out.println("预约人:" + username);
System.out.println("实验室编号:" + labId);
System.out.println("开始时间:" + startTime);
System.out.println("结束时间:" + endTime);
System.out.println("用途:" + purpose);
}
}

@ -0,0 +1,31 @@
package com.ssm.di;
public class Laboratory {
private String labId;
private String labName;
private String location;
private int capacity;
private String status;
public Laboratory() {}
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public String getLabName() { return labName; }
public void setLabName(String labName) { this.labName = labName; }
public String getLocation() { return location; }
public void setLocation(String location) { this.location = location; }
public int getCapacity() { return capacity; }
public void setCapacity(int capacity) { this.capacity = capacity; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public void printInfo() {
System.out.println("实验室信息:");
System.out.println("实验室编号:" + labId);
System.out.println("实验室名称:" + labName);
System.out.println("位置:" + location);
System.out.println("容纳人数:" + capacity);
System.out.println("状态:" + status);
}
}

@ -0,0 +1,31 @@
package com.ssm.di;
public class Material {
private String materialId;
private String materialName;
private String type;
private int stock;
private String unit;
public Material() {}
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getMaterialName() { return materialName; }
public void setMaterialName(String materialName) { this.materialName = materialName; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public int getStock() { return stock; }
public void setStock(int stock) { this.stock = stock; }
public String getUnit() { return unit; }
public void setUnit(String unit) { this.unit = unit; }
public void printInfo() {
System.out.println("材料信息:");
System.out.println("材料编号:" + materialId);
System.out.println("材料名称:" + materialName);
System.out.println("类型:" + type);
System.out.println("库存:" + stock);
System.out.println("单位:" + unit);
}
}

@ -0,0 +1,37 @@
package com.ssm.di;
import java.util.Date;
public class MaterialRecord {
private String recordId;
private String materialId;
private String operator;
private int nums;
private Date operateDate;
private String type;
public MaterialRecord() {}
public String getRecordId() { return recordId; }
public void setRecordId(String recordId) { this.recordId = recordId; }
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getOperator() { return operator; }
public void setOperator(String operator) { this.operator = operator; }
public int getNums() { return nums; }
public void setNums(int nums) { this.nums = nums; }
public Date getOperateDate() { return operateDate; }
public void setOperateDate(Date operateDate) { this.operateDate = operateDate; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public void printInfo() {
System.out.println("材料出入库记录:");
System.out.println("记录编号:" + recordId);
System.out.println("材料编号:" + materialId);
System.out.println("操作人:" + operator);
System.out.println("操作数量:" + nums);
System.out.println("操作日期:" + operateDate);
System.out.println("操作类型:" + type);
}
}

@ -0,0 +1,32 @@
package com.ssm.di;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDI {
public static void main(String[] args) {
// 1. 加载配置文件创建Spring容器
ApplicationContext context = new ClassPathXmlApplicationContext("bean-di-xml.xml");
// 2. 获取Bean并调用printInfo()输出信息
System.out.println("===== 用户管理模块 =====");
User user = (User) context.getBean("user");
user.printInfo();
System.out.println("\n===== 材料管理模块 =====");
Material material = (Material) context.getBean("material");
material.printInfo();
System.out.println("\n===== 材料出入库管理模块 =====");
MaterialRecord record = (MaterialRecord) context.getBean("materialRecord");
record.printInfo();
System.out.println("\n===== 预约管理模块 =====");
Appointment appointment = (Appointment) context.getBean("appointment");
appointment.printInfo();
System.out.println("\n===== 实验室管理模块 =====");
Laboratory lab = (Laboratory) context.getBean("laboratory");
lab.printInfo();
}
}

@ -0,0 +1,34 @@
package com.ssm.di;
public class User {
private String username;
private String userpass;
private String truename;
private int age;
private String role;
// 无参构造setter注入必须要有
public User() {}
// Getter & Setter
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 int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getRole() { return role; }
public void setRole(String role) { this.role = role; }
// 按要求新增printInfo()方法
public void printInfo() {
System.out.println("用户信息:");
System.out.println("用户名:" + username);
System.out.println("密码:" + userpass);
System.out.println("真实姓名:" + truename);
System.out.println("年龄:" + age);
System.out.println("角色:" + role);
}
}

@ -0,0 +1,51 @@
package com.ssm.di.annotation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component("appointment")
public class Appointment {
@Value("A001")
private String appointmentId;
@Value("孙佳兴")
private String username;
@Value("L001")
private String labId;
@Value("#{new java.util.Date()}")
private Date startTime;
@Value("#{new java.util.Date()}")
private Date endTime;
@Value("化学实验")
private String purpose;
public Appointment() {}
public String getAppointmentId() { return appointmentId; }
public void setAppointmentId(String appointmentId) { this.appointmentId = appointmentId; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public Date getStartTime() { return startTime; }
public void setStartTime(Date startTime) { this.startTime = startTime; }
public Date getEndTime() { return endTime; }
public void setEndTime(Date endTime) { this.endTime = endTime; }
public String getPurpose() { return purpose; }
public void setPurpose(String purpose) { this.purpose = purpose; }
public void printInfo() {
System.out.println("预约信息:");
System.out.println("预约编号:" + appointmentId);
System.out.println("预约人:" + username);
System.out.println("实验室编号:" + labId);
System.out.println("开始时间:" + startTime);
System.out.println("结束时间:" + endTime);
System.out.println("用途:" + purpose);
}
}

@ -1,39 +0,0 @@
package com.ssm.di.annotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Course {
private String courseId;
private String courseName;
private int credit;
// 自动注入Teacher对象核心注解
@Autowired
private Teacher teacher;
// 无参构造
public Course() {}
// Setter方法XML给属性赋值
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public void setCredit(int credit) {
this.credit = credit;
}
// 输出方法和之前XML版本的格式完全一致
public void printInfo() {
System.out.println("课程编号:" + courseId);
System.out.println("课程名称:" + courseName);
System.out.println("学分:" + credit);
System.out.println("授课教师信息:工号:" + teacher.getTeacherId() + ",姓名:" + teacher.getName() + ",职称:" + teacher.getTitle());
}
}

@ -0,0 +1,44 @@
package com.ssm.di.annotation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component("laboratory")
public class Laboratory {
@Value("L001")
private String labId;
@Value("化学实验室1号")
private String labName;
@Value("实验楼3楼")
private String location;
@Value("30")
private int capacity;
@Value("空闲")
private String status;
public Laboratory() {}
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public String getLabName() { return labName; }
public void setLabName(String labName) { this.labName = labName; }
public String getLocation() { return location; }
public void setLocation(String location) { this.location = location; }
public int getCapacity() { return capacity; }
public void setCapacity(int capacity) { this.capacity = capacity; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public void printInfo() {
System.out.println("实验室信息:");
System.out.println("实验室编号:" + labId);
System.out.println("实验室名称:" + labName);
System.out.println("位置:" + location);
System.out.println("容纳人数:" + capacity);
System.out.println("状态:" + status);
}
}

@ -0,0 +1,44 @@
package com.ssm.di.annotation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component("material")
public class Material {
@Value("M001")
private String materialId;
@Value("试管")
private String materialName;
@Value("玻璃耗材")
private String type;
@Value("100")
private int stock;
@Value("个")
private String unit;
public Material() {}
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getMaterialName() { return materialName; }
public void setMaterialName(String materialName) { this.materialName = materialName; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public int getStock() { return stock; }
public void setStock(int stock) { this.stock = stock; }
public String getUnit() { return unit; }
public void setUnit(String unit) { this.unit = unit; }
public void printInfo() {
System.out.println("材料信息:");
System.out.println("材料编号:" + materialId);
System.out.println("材料名称:" + materialName);
System.out.println("类型:" + type);
System.out.println("库存:" + stock);
System.out.println("单位:" + unit);
}
}

@ -0,0 +1,51 @@
package com.ssm.di.annotation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component("materialRecord")
public class MaterialRecord {
@Value("R001")
private String recordId;
@Value("M001")
private String materialId;
@Value("喻廷屿")
private String operator;
@Value("20")
private int nums;
@Value("#{new java.util.Date()}")
private Date operateDate;
@Value("入库")
private String type;
public MaterialRecord() {}
public String getRecordId() { return recordId; }
public void setRecordId(String recordId) { this.recordId = recordId; }
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getOperator() { return operator; }
public void setOperator(String operator) { this.operator = operator; }
public int getNums() { return nums; }
public void setNums(int nums) { this.nums = nums; }
public Date getOperateDate() { return operateDate; }
public void setOperateDate(Date operateDate) { this.operateDate = operateDate; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public void printInfo() {
System.out.println("材料出入库记录:");
System.out.println("记录编号:" + recordId);
System.out.println("材料编号:" + materialId);
System.out.println("操作人:" + operator);
System.out.println("操作数量:" + nums);
System.out.println("操作日期:" + operateDate);
System.out.println("操作类型:" + type);
}
}

@ -1,40 +0,0 @@
package com.ssm.di.annotation;
import org.springframework.stereotype.Component;
// 让Spring自动扫描并创建这个Bean
@Component
public class Teacher {
private String teacherId;
private String name;
private String title;
// 无参构造Spring需要
public Teacher() {}
// Setter方法可选这里我们用XML给属性赋值
public void setTeacherId(String teacherId) {
this.teacherId = teacherId;
}
public void setName(String name) {
this.name = name;
}
public void setTitle(String title) {
this.title = title;
}
// Getter方法供Course调用
public String getTeacherId() {
return teacherId;
}
public String getName() {
return name;
}
public String getTitle() {
return title;
}
}

@ -1,11 +1,31 @@
package com.ssm.di.annotation;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestAnnotation {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-di-annotation.xml");
Course course = ac.getBean("course", Course.class);
course.printInfo();
// 加载Spring配置
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("===== 用户管理模块 =====");
User user = (User) context.getBean("user");
user.printInfo();
System.out.println("\n===== 材料管理模块 =====");
Material material = (Material) context.getBean("material");
material.printInfo();
System.out.println("\n===== 材料出入库管理模块 =====");
MaterialRecord record = (MaterialRecord) context.getBean("materialRecord");
record.printInfo();
System.out.println("\n===== 预约管理模块 =====");
Appointment appointment = (Appointment) context.getBean("appointment");
appointment.printInfo();
System.out.println("\n===== 实验室管理模块 =====");
Laboratory lab = (Laboratory) context.getBean("laboratory");
lab.printInfo();
}
}

@ -0,0 +1,44 @@
package com.ssm.di.annotation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component("user")
public class User {
@Value("daiyuhang")
private String username;
@Value("123456")
private String userpass;
@Value("代宇航")
private String truename;
@Value("20")
private int age;
@Value("管理员")
private String role;
public User() {}
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 int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getRole() { return role; }
public void setRole(String role) { this.role = role; }
public void printInfo() {
System.out.println("用户信息:");
System.out.println("用户名:" + username);
System.out.println("密码:" + userpass);
System.out.println("真实姓名:" + truename);
System.out.println("年龄:" + age);
System.out.println("角色:" + role);
}
}

@ -1,36 +0,0 @@
package com.ssm.di.xml;
public class Course {
private String courseId; // 课程编号
private String courseName; // 课程名称
private int credit; // 学分
private Teacher teacher; // 授课教师
// Spring 必须的无参构造
public Course() {}
// Setter 方法供XML注入使用
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public void setCredit(int credit) {
this.credit = credit;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
// 修改为和第一张截图完全一致的输出格式
public void printInfo() {
System.out.println("课程编号:" + courseId);
System.out.println("课程名称:" + courseName);
System.out.println("学分:" + credit);
System.out.println("授课教师信息:工号:" + teacher.getTeacherId() + ",姓名:" + teacher.getName() + ",职称:" + teacher.getTitle());
}
}

@ -1,36 +0,0 @@
package com.ssm.di.xml;
public class Teacher {
private String teacherId; // 工号
private String name; // 姓名
private String title; // 职称
// Spring 必须的无参构造
public Teacher() {}
// Setter 方法供XML注入使用
public void setTeacherId(String teacherId) {
this.teacherId = teacherId;
}
public void setName(String name) {
this.name = name;
}
public void setTitle(String title) {
this.title = title;
}
// Getter 方法供Course调用
public String getTeacherId() {
return teacherId;
}
public String getName() {
return name;
}
public String getTitle() {
return title;
}
}

@ -1,17 +0,0 @@
package com.ssm.di.xml;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDI {
public static void main(String[] args) {
// 1. 加载Spring配置文件
ApplicationContext context = new ClassPathXmlApplicationContext("bean-di-xml.xml");
// 2. 获取Course对象
Course course = context.getBean("course", Course.class);
// 3. 调用方法,输出信息
course.printInfo();
}
}

@ -1,16 +0,0 @@
package com.ssm.first;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestFirst {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-first.xml");
System.out.println("Hello Spring!");
System.out.println("Hello Spring!");
System.out.println("Hello Spring!");
System.out.println("Hello Spring!");
System.out.println("Hello Spring!");
}
}

@ -0,0 +1,40 @@
package com.ssm.ioc;
import java.util.Date;
public class Appointment {
private String appointmentId;
private String username;
private String labId;
private Date startTime;
private Date endTime;
private String purpose;
public Appointment() {
}
public String getAppointmentId() { return appointmentId; }
public void setAppointmentId(String appointmentId) { this.appointmentId = appointmentId; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public Date getStartTime() { return startTime; }
public void setStartTime(Date startTime) { this.startTime = startTime; }
public Date getEndTime() { return endTime; }
public void setEndTime(Date endTime) { this.endTime = endTime; }
public String getPurpose() { return purpose; }
public void setPurpose(String purpose) { this.purpose = purpose; }
@Override
public String toString() {
return "Appointment{" +
"appointmentId='" + appointmentId + '\'' +
", username='" + username + '\'' +
", labId='" + labId + '\'' +
", startTime=" + startTime +
", endTime=" + endTime +
", purpose='" + purpose + '\'' +
'}';
}
}

@ -1,65 +0,0 @@
package com.ssm.ioc;
/**
*
*/
public class Goods {
private String goodsId; // 商品ID
private String goodsName; // 商品名
private double price; // 价格
private String brand; // 品牌
private int stock; // 库存
public Goods() {}
public String getGoodsId() {
return goodsId;
}
public void setGoodsId(String goodsId) {
this.goodsId = goodsId;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
@Override
public String toString() {
return "Goods{" +
"goodsId='" + goodsId + '\'' +
", goodsName='" + goodsName + '\'' +
", price=" + price +
", brand='" + brand + '\'' +
", stock=" + stock +
'}';
}
}

@ -0,0 +1,34 @@
package com.ssm.ioc;
public class Laboratory {
private String labId;
private String labName;
private String location;
private int capacity;
private String status;
public Laboratory() {
}
public String getLabId() { return labId; }
public void setLabId(String labId) { this.labId = labId; }
public String getLabName() { return labName; }
public void setLabName(String labName) { this.labName = labName; }
public String getLocation() { return location; }
public void setLocation(String location) { this.location = location; }
public int getCapacity() { return capacity; }
public void setCapacity(int capacity) { this.capacity = capacity; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
@Override
public String toString() {
return "Laboratory{" +
"labId='" + labId + '\'' +
", labName='" + labName + '\'' +
", location='" + location + '\'' +
", capacity=" + capacity +
", status='" + status + '\'' +
'}';
}
}

@ -0,0 +1,34 @@
package com.ssm.ioc;
public class Material {
private String materialId;
private String materialName;
private String type;
private int stock;
private String unit;
public Material() {
}
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getMaterialName() { return materialName; }
public void setMaterialName(String materialName) { this.materialName = materialName; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public int getStock() { return stock; }
public void setStock(int stock) { this.stock = stock; }
public String getUnit() { return unit; }
public void setUnit(String unit) { this.unit = unit; }
@Override
public String toString() {
return "Material{" +
"materialId='" + materialId + '\'' +
", materialName='" + materialName + '\'' +
", type='" + type + '\'' +
", stock=" + stock +
", unit='" + unit + '\'' +
'}';
}
}

@ -0,0 +1,40 @@
package com.ssm.ioc;
import java.util.Date;
public class MaterialRecord {
private String recordId;
private String materialId;
private String operator;
private int nums;
private Date operateDate;
private String type;
public MaterialRecord() {
}
public String getRecordId() { return recordId; }
public void setRecordId(String recordId) { this.recordId = recordId; }
public String getMaterialId() { return materialId; }
public void setMaterialId(String materialId) { this.materialId = materialId; }
public String getOperator() { return operator; }
public void setOperator(String operator) { this.operator = operator; }
public int getNums() { return nums; }
public void setNums(int nums) { this.nums = nums; }
public Date getOperateDate() { return operateDate; }
public void setOperateDate(Date operateDate) { this.operateDate = operateDate; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
@Override
public String toString() {
return "MaterialRecord{" +
"recordId='" + recordId + '\'' +
", materialId='" + materialId + '\'' +
", operator='" + operator + '\'' +
", nums=" + nums +
", operateDate=" + operateDate +
", type='" + type + '\'' +
'}';
}
}

@ -1,67 +0,0 @@
package com.ssm.ioc;
import java.util.Date;
/**
*
*/
public class Order {
private String id; // 订单编号
private String username; // 下单人
private String goodsname; // 商品名称
private int nums; // 购买数量
private Date date; // 下单日期
public Order() {}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getGoodsname() {
return goodsname;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
public int getNums() {
return nums;
}
public void setNums(int nums) {
this.nums = nums;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@Override
public String toString() {
return "Order{" +
"id='" + id + '\'' +
", username='" + username + '\'' +
", goodsname='" + goodsname + '\'' +
", nums=" + nums +
", date=" + date +
'}';
}
}

@ -1,65 +0,0 @@
package com.ssm.ioc;
/**
*
*/
public class Teacher {
private String teacherId; // 工号
private String name; // 姓名
private String course; // 授课课程
private String department; // 部门
private int workAge; // 教龄
public Teacher() {}
public String getTeacherId() {
return teacherId;
}
public void setTeacherId(String teacherId) {
this.teacherId = teacherId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int getWorkAge() {
return workAge;
}
public void setWorkAge(int workAge) {
this.workAge = workAge;
}
@Override
public String toString() {
return "Teacher{" +
"teacherId='" + teacherId + '\'' +
", name='" + name + '\'' +
", course='" + course + '\'' +
", department='" + department + '\'' +
", workAge=" + workAge +
'}';
}
}

@ -3,31 +3,24 @@ package com.ssm.ioc;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* IOC Bean
*/
public class TestIoc {
public static void main(String[] args) {
// 1. 加载Spring配置文件
ApplicationContext context = new ClassPathXmlApplicationContext("bean-ioc.xml");
// 配置文件在 src 根目录,直接写文件名
ApplicationContext context = new ClassPathXmlApplicationContext("bean-di-xml.xml");
// 2. 获取Bean
User user = (User) context.getBean("user");
Order order = (Order) context.getBean("order");
Goods goods = (Goods) context.getBean("goods");
Teacher teacher = (Teacher) context.getBean("teacher");
System.out.println("===== 用户管理模块 =====");
System.out.println(context.getBean("user"));
// 3. 输出所有对象信息
System.out.println("===== 用户信息 =====");
System.out.println(user);
System.out.println("\n===== 材料管理模块 =====");
System.out.println(context.getBean("material"));
System.out.println("\n===== 订单信息 =====");
System.out.println(order);
System.out.println("\n===== 材料出入库管理模块 =====");
System.out.println(context.getBean("materialRecord"));
System.out.println("\n===== 商品信息 =====");
System.out.println(goods);
System.out.println("\n===== 预约管理模块 =====");
System.out.println(context.getBean("appointment"));
System.out.println("\n===== 教师信息 =====");
System.out.println(teacher);
System.out.println("\n===== 实验室管理模块 =====");
System.out.println(context.getBean("laboratory"));
}
}

@ -1,61 +1,26 @@
package com.ssm.ioc;
/**
*
*/
public class User {
// 属性 ≥4个
private String username; // 用户名
private String userpass; // 密码
private String truename; // 真实姓名
private int age; // 年龄
private String email; // 邮箱第5个
private String username;
private String userpass;
private String truename;
private int age;
private String role;
public User() {
}
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 int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getRole() { return role; }
public void setRole(String role) { this.role = role; }
// 无参构造Spring必须
public User() {}
// getter & setter
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
// 输出对象信息
@Override
public String toString() {
return "User{" +
@ -63,7 +28,7 @@ public class User {
", userpass='" + userpass + '\'' +
", truename='" + truename + '\'' +
", age=" + age +
", email='" + email + '\'' +
", role='" + role + '\'' +
'}';
}
}
Loading…
Cancel
Save