課程管理模塊開發(fā)
完成課程管理功能開發(fā),耗時(shí) 1 天,累計(jì)耗時(shí) 2 天,剩余 8 天。實(shí)現(xiàn)內(nèi)容包括:
設(shè)計(jì)課程實(shí)體Course和員工課程關(guān)聯(lián)實(shí)體EmployeeCourse,建立多對多關(guān)系。
開發(fā)管理員端課程 CRUD 功能,支持課程添加、刪除和列表展示。
實(shí)現(xiàn)員工端選課邏輯,通過EmployeeCourse表記錄選課狀態(tài),支持選課和退選操作。
遇到的困難
多對多關(guān)聯(lián)映射:EmployeeCourse表初始設(shè)計(jì)時(shí)未正確配置@ManyToOne關(guān)系,導(dǎo)致保存選課記錄時(shí)外鍵為空。通過添加@JoinColumn明確外鍵列名(如employee_id和course_id)解決。
前端內(nèi)容展示:課程內(nèi)容較長時(shí),頁面布局混亂。通過添加 “展開 / 收起” 按鈕(toggleContent函數(shù))和 CSS 文本截?cái)嗵幚恚瑑?yōu)化內(nèi)容預(yù)覽效果。
今天的任務(wù)(第 3 天)
開發(fā)員工管理模塊,實(shí)現(xiàn)員工列表查看和刪除功能,重點(diǎn)校驗(yàn)刪除時(shí)是否存在選課記錄。
設(shè)計(jì)員工與課程的關(guān)聯(lián)查詢,在管理端展示員工選課情況。
核心代碼示例
課程實(shí)體類(Course.java)
@Entity
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String teacher;
@Column(columnDefinition = "TEXT")
private String content;
// 構(gòu)造方法、getter/setter省略
}
員工課程關(guān)聯(lián)實(shí)體(EmployeeCourse.java)
@Entity
@Table(name = "employee_course")
public class EmployeeCourse {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "employee_id", nullable = false)
private User employee;
@ManyToOne
@JoinColumn(name = "course_id", nullable = false)
private Course course;
private boolean active = true;
private LocalDateTime selectedAt = LocalDateTime.now();
// 構(gòu)造方法、getter/setter省略
}
選課控制器(EmployeeController.java)
@PostMapping("/select-course")
public String selectCourse(@RequestParam Integer courseId, HttpSession session) {
User employee = getCurrentEmployee(session);
employeeService.selectCourse(employee.getId(), courseId);
return "redirect:/employee/course";
}

浙公網(wǎng)安備 33010602011771號(hào)