String sql3="insert into teacher_student (teacher_id,student_id) values(?,?)";

教师信息管理系统
本文介绍了一个使用Java实现的教师信息管理系统,该系统通过DAO模式管理教师及其相关学生的信息,并利用Apache Commons DbUtils简化数据库操作。文章详细展示了如何进行教师信息的添加及根据ID查询教师及其学生信息的具体实现。
package com.tfy.itheima.dao.impl;


import java.util.List;


import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;


import com.tfy.itheima.domain.Student;
import com.tfy.itheima.domain.Teacher;
import com.tfy.itheima.jdbc.util.DbcpUtil;


public class TeacherDaoImpl {
private QueryRunner qr=new QueryRunner(DbcpUtil.getDataSource());
public void addTeacher(Teacher t){
try{

//保存教师的基本信息
String sql1="insert into teacher (id,name,salary) values(?,?,?)";
Object []params1={t.getId(),t.getName(),t.getSalary()};

qr.update(sql1, params1);
//如果有学生的话,则保存学生的基本信息,并在第三方的表中建立关系
List<Student> students = t.getStudents();
if(students!=null && students.size()>0){
String sql2="insert into student (id,name,grade) values(?,?,?)";
String sql3="insert into teacher_student (teacher_id,student_id) values(?,?)";
Object [][]params2=new Object[students.size()][];
Object [][]params3=new Object[students.size()][];
for(int i=0;i<students.size();i++){
Student s = students.get(i);
params2[i]=new Object[]{s.getId(),s.getName(),s.getGrade()};
params3[i]=new Object[]{t.getId(),s.getId()};
}
qr.batch(sql2, params2);
qr.batch(sql3, params3);
}

}catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e);
}


}
//把学生的基本信息查询出来
public Teacher findTeacherById(Integer teacherId){
try{
String sql1="select * from teacher where id=?";
Teacher t = qr.query(sql1, new BeanHandler<Teacher>(Teacher.class),teacherId);
//查询学生基本信息
if(t!=null){
// String sql2="select s.* from student s ,teacher_student ts where s.id=ts.student_id and ts.teacher_id=?";
// String sql2="select s.* from student s inner join teacher_student ts on s.id=ts.student_id where ts.teacher_id=?";
String sql2="select * from student where id in(select student_id from teacher_student where teacher_id=?)";
List<Student> students = qr.query(sql2, new BeanListHandler<Student>(Student.class), teacherId);
t.setStudents(students);


}
return t;

}catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e);
}

}
}
package schoolclass; import java.sql.Connection; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import util.DBConnection; public class SchoolClassDaoImpl implements SchoolClassDao { @Override public void insert(SchoolClass clazz) throws Exception { String sql = "INSERT INTO school_classes (id, class_name, grade, homeroom_teacher_id, enrollment_year, major, department, current_student_count, max_capacity, created_at, is_active) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try (Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, clazz.getId()); ps.setString(2, clazz.getClassName()); ps.setString(3, clazz.getGrade()); ps.setInt(4, clazz.getHomeroomTeacherId()); ps.setInt(5, clazz.getEnrollmentYear()); ps.setString(6, clazz.getMajor()); ps.setString(7, clazz.getDepartment()); ps.setInt(8, clazz.getCurrentStudentCount()); ps.setInt(9, clazz.getMaxCapacity()); ps.setDate(10, Date.valueOf(clazz.getCreatedAt())); ps.setBoolean(11, clazz.isActive()); ps.executeUpdate(); } } @Override public void update(SchoolClass clazz) throws Exception { String sql = "UPDATE school_classes SET class_name=?, grade=?, homeroom_teacher_id=?, enrollment_year=?, major=?, department=?, current_student_count=?, max_capacity=?, created_at=?, is_active=? WHERE id=?"; try (Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, clazz.getClassName()); ps.setString(2, clazz.getGrade()); ps.setInt(3, clazz.getHomeroomTeacherId()); ps.setInt(4, clazz.getEnrollmentYear()); ps.setString(5, clazz.getMajor()); ps.setString(6, clazz.getDepartment()); ps.setInt(7, clazz.getCurrentStudentCount()); ps.setInt(8, clazz.getMaxCapacity()); ps.setDate(9, Date.valueOf(clazz.getCreatedAt())); ps.setBoolean(10, clazz.isActive()); ps.setInt(11, clazz.getId()); ps.executeUpdate(); } } @Override public void delete(int id) throws Exception { String sql = "DELETE FROM school_classes WHERE id=?"; try (Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, id); ps.executeUpdate(); } } @Override public SchoolClass findById(int id) throws Exception { String sql = "SELECT * FROM school_classes WHERE id=?"; try (Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, id); ResultSet rs = ps.executeQuery(); if (rs.next()) { return mapRowToClass(rs); } return null; } } @Override public List<SchoolClass> findAll() throws Exception { String sql = "SELECT * FROM school_classes"; List<SchoolClass> list = new ArrayList<>(); try (Connection conn = DBConnection.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql)) { while (rs.next()) { list.add(mapRowToClass(rs)); } } return list; } private SchoolClass mapRowToClass(ResultSet rs) throws SQLException { SchoolClass c = new SchoolClass(); c.setId(rs.getInt("id")); c.setClassName(rs.getString("class_name")); c.setGrade(rs.getString("grade")); c.setHomeroomTeacherId(rs.getInt("homeroom_teacher_id")); c.setEnrollmentYear(rs.getInt("enrollment_year")); c.setMajor(rs.getString("major")); c.setDepartment(rs.getString("department")); c.setCurrentStudentCount(rs.getInt("current_student_count")); c.setMaxCapacity(rs.getInt("max_capacity")); c.setCreatedAt(rs.getDate("created_at").toLocalDate()); c.setActive(rs.getBoolean("is_active")); return c; } } 根据这个代码生成GUI界面代码
最新发布
11-20
-- 最终推荐方案:CTE + ARRAY JOIN,性能和可读性最佳 INSERT INTO `default`.temp_teacher_summary_stat WITH AggGrowthData AS ( SELECT teacherProvinceId, teacherCityId, teacherCountyId, teacherSchoolId, grouping(teacherProvinceId) AS g_province, grouping(teacherCityId) AS g_city, grouping(teacherCountyId) AS g_county, grouping(teacherSchoolId) AS g_school, -- 将所有指标打包成一个元组数组 arrayZip( -- 键数组 [ &#39;newTeacherSumCount&#39;, &#39;newTeacherPassedCount&#39;, &#39;newTeacherNotPassedCount&#39;, &#39;newTeacherPendingCount&#39;, &#39;growthTeamTeacherSumCount&#39;, &#39;growthTeamTeacherPassedCount&#39;, &#39;growthTeamTeacherNotPassedCount&#39;, &#39;growthTeamTeacherPendingCount&#39;, &#39;youngTeacherBasicSkillsSumCount&#39;, &#39;youngTeacherBasicSkillsPassedCount&#39;, &#39;youngTeacherBasicSkillsNotPassedCount&#39;, &#39;youngTeacherBasicSkillsPendingCount&#39;, &#39;highQualityClassCompetitionSumCount&#39;, &#39;highQualityClassCompetitionPassedCount&#39;, &#39;highQualityClassCompetitionNotPassedCount&#39;, &#39;highQualityClassCompetitionPendingCount&#39;, &#39;teachingExpertSumCount&#39;, &#39;teachingExpertPassedCount&#39;, &#39;teachingExpertNotPassedCount&#39;, &#39;teachingExpertPendingCount&#39;, &#39;subjectLeaderSumCount&#39;, &#39;subjectLeaderPassedCount&#39;, &#39;subjectLeaderNotPassedCount&#39;, &#39;subjectLeaderPendingCount&#39;, &#39;qingdaoMasterTeacherCandidateSumCount&#39;, &#39;qingdaoMasterTeacherCandidatePassedCount&#39;, &#39;qingdaoMasterTeacherCandidateNotPassedCount&#39;, &#39;qingdaoMasterTeacherCandidatePendingCount&#39;, &#39;qingdaoMasterTeacherSumCount&#39;, &#39;qingdaoMasterTeacherPassedCount&#39;, &#39;qingdaoMasterTeacherNotPassedCount&#39;, &#39;qingdaoMasterTeacherPendingCount&#39;, &#39;lifelongQingdaoMasterTeacherSumCount&#39;, &#39;lifelongQingdaoMasterTeacherPassedCount&#39;, &#39;lifelongQingdaoMasterTeacherNotPassedCount&#39;, &#39;lifelongQingdaoMasterTeacherPendingCount&#39;, &#39;qingdaoFamousClassTeacherSumCount&#39;, &#39;qingdaoFamousClassTeacherPassedCount&#39;, &#39;qingdaoFamousClassTeacherNotPassedCount&#39;, &#39;qingdaoFamousClassTeacherPendingCount&#39;, &#39;lifelongQingdaoFamousClassTeacherSumCount&#39;, &#39;lifelongQingdaoFamousClassTeacherPassedCount&#39;, &#39;lifelongQingdaoFamousClassTeacherNotPassedCount&#39;, &#39;lifelongQingdaoFamousClassTeacherPendingCount&#39;, &#39;qingdaoFamousPrincipalSumCount&#39;, &#39;qingdaoFamousPrincipalPassedCount&#39;, &#39;qingdaoFamousPrincipalNotPassedCount&#39;, &#39;qingdaoFamousPrincipalPendingCount&#39;, &#39;lifelongQingdaoFamousPrincipalSumCount&#39;, &#39;lifelongQingdaoFamousPrincipalPassedCount&#39;, &#39;lifelongQingdaoFamousPrincipalNotPassedCount&#39;, &#39;lifelongQingdaoFamousPrincipalPendingCount&#39;, &#39;provincialSpecialTeacherSumCount&#39;, &#39;provincialSpecialTeacherPassedCount&#39;, &#39;provincialSpecialTeacherNotPassedCount&#39;, &#39;provincialSpecialTeacherPendingCount&#39;, &#39;qiluMasterTeacherCandidateSumCount&#39;, &#39;qiluMasterTeacherCandidatePassedCount&#39;, &#39;qiluMasterTeacherCandidateNotPassedCount&#39;, &#39;qiluMasterTeacherCandidatePendingCount&#39;, &#39;qiluMasterTeacherSumCount&#39;, &#39;qiluMasterTeacherPassedCount&#39;, &#39;qiluMasterTeacherNotPassedCount&#39;, &#39;qiluMasterTeacherPendingCount&#39;, &#39;qiluFamousPrincipalCandidateSumCount&#39;, &#39;qiluFamousPrincipalCandidatePassedCount&#39;, &#39;qiluFamousPrincipalCandidateNotPassedCount&#39;, &#39;qiluFamousPrincipalCandidatePendingCount&#39;, &#39;qiluFamousPrincipalSumCount&#39;, &#39;qiluFamousPrincipalPassedCount&#39;, &#39;qiluFamousPrincipalNotPassedCount&#39;, &#39;qiluFamousPrincipalPendingCount&#39;, &#39;nationalTeachingMasterSumCount&#39;, &#39;nationalTeachingMasterPassedCount&#39;, &#39;nationalTeachingMasterNotPassedCount&#39;, &#39;nationalTeachingMasterPendingCount&#39;, &#39;growthDevelopmentStageSumCount&#39;, &#39;growthDevelopmentStagePassedCount&#39;, &#39;growthDevelopmentStageNotPassedCount&#39;, &#39;growthDevelopmentStagePendingCount&#39;, &#39;qingdaoMasterStudioHostSumCount&#39;, &#39;qingdaoMasterStudioHostPassedCount&#39;, &#39;qingdaoMasterStudioHostNotPassedCount&#39;, &#39;qingdaoMasterStudioHostPendingCount&#39;, &#39;qingdaoMasterStudioMemberSumCount&#39;, &#39;qingdaoMasterStudioMemberPassedCount&#39;, &#39;qingdaoMasterStudioMemberNotPassedCount&#39;, &#39;qingdaoMasterStudioMemberPendingCount&#39;, &#39;qingdaoFamousClassTeacherStudioHostSumCount&#39;, &#39;qingdaoFamousClassTeacherStudioHostPassedCount&#39;, &#39;qingdaoFamousClassTeacherStudioHostNotPassedCount&#39;, &#39;qingdaoFamousClassTeacherStudioHostPendingCount&#39;, &#39;qingdaoFamousClassTeacherStudioMemberSumCount&#39;, &#39;qingdaoFamousClassTeacherStudioMemberPassedCount&#39;, &#39;qingdaoFamousClassTeacherStudioMemberNotPassedCount&#39;, &#39;qingdaoFamousClassTeacherStudioMemberPendingCount&#39;, &#39;qingdaoFamousPrincipalStudioHostSumCount&#39;, &#39;qingdaoFamousPrincipalStudioHostPassedCount&#39;, &#39;qingdaoFamousPrincipalStudioHostNotPassedCount&#39;, &#39;qingdaoFamousPrincipalStudioHostPendingCount&#39;, &#39;qingdaoFamousPrincipalStudioMemberSumCount&#39;, &#39;qingdaoFamousPrincipalStudioMemberPassedCount&#39;, &#39;qingdaoFamousPrincipalStudioMemberNotPassedCount&#39;, &#39;qingdaoFamousPrincipalStudioMemberPendingCount&#39;, &#39;qiluMasterNavigationStudioHostSumCount&#39;, &#39;qiluMasterNavigationStudioHostPassedCount&#39;, &#39;qiluMasterNavigationStudioHostNotPassedCount&#39;, &#39;qiluMasterNavigationStudioHostPendingCount&#39;, &#39;qiluMasterNavigationStudioMemberSumCount&#39;, &#39;qiluMasterNavigationStudioMemberPassedCount&#39;, &#39;qiluMasterNavigationStudioMemberNotPassedCount&#39;, &#39;qiluMasterNavigationStudioMemberPendingCount&#39;, &#39;qiluFamousPrincipalStudioHostSumCount&#39;, &#39;qiluFamousPrincipalStudioHostPassedCount&#39;, &#39;qiluFamousPrincipalStudioHostNotPassedCount&#39;, &#39;qiluFamousPrincipalStudioHostPendingCount&#39;, &#39;qiluFamousPrincipalStudioMemberSumCount&#39;, &#39;qiluFamousPrincipalStudioMemberPassedCount&#39;, &#39;qiluFamousPrincipalStudioMemberNotPassedCount&#39;, &#39;qiluFamousPrincipalStudioMemberPendingCount&#39;, &#39;shandongVocationalMasterStudioHostSumCount&#39;, &#39;shandongVocationalMasterStudioHostPassedCount&#39;, &#39;shandongVocationalMasterStudioHostNotPassedCount&#39;, &#39;shandongVocationalMasterStudioHostPendingCount&#39;, &#39;shandongVocationalMasterStudioMemberSumCount&#39;, &#39;shandongVocationalMasterStudioMemberPassedCount&#39;, &#39;shandongVocationalMasterStudioMemberNotPassedCount&#39;, &#39;shandongVocationalMasterStudioMemberPendingCount&#39;, &#39;shandongVocationalSkillPlatformHostSumCount&#39;, &#39;shandongVocationalSkillPlatformHostPassedCount&#39;, &#39;shandongVocationalSkillPlatformHostNotPassedCount&#39;, &#39;shandongVocationalSkillPlatformHostPendingCount&#39;, &#39;shandongVocationalSkillPlatformMemberSumCount&#39;, &#39;shandongVocationalSkillPlatformMemberPassedCount&#39;, &#39;shandongVocationalSkillPlatformMemberNotPassedCount&#39;, &#39;shandongVocationalSkillPlatformMemberPendingCount&#39;, &#39;provincialSpecialTeacherWorkshopHostSumCount&#39;, &#39;provincialSpecialTeacherWorkshopHostPassedCount&#39;, &#39;provincialSpecialTeacherWorkshopHostNotPassedCount&#39;, &#39;provincialSpecialTeacherWorkshopHostPendingCount&#39;, &#39;provincialSpecialTeacherWorkshopMemberSumCount&#39;, &#39;provincialSpecialTeacherWorkshopMemberPassedCount&#39;, &#39;provincialSpecialTeacherWorkshopMemberNotPassedCount&#39;, &#39;provincialSpecialTeacherWorkshopMemberPendingCount&#39;, &#39;provincialSpecialTeacherWorkshopGroupMemberSumCount&#39;, &#39;provincialSpecialTeacherWorkshopGroupMemberPassedCount&#39;, &#39;provincialSpecialTeacherWorkshopGroupMemberNotPassedCount&#39;, &#39;provincialSpecialTeacherWorkshopGroupMemberPendingCount&#39;, &#39;shandongProvincialRemoteWorkshopHostSumCount&#39;, &#39;shandongProvincialRemoteWorkshopHostPassedCount&#39;, &#39;shandongProvincialRemoteWorkshopHostNotPassedCount&#39;, &#39;shandongProvincialRemoteWorkshopHostPendingCount&#39;, &#39;shandongProvincialRemoteWorkshopMemberSumCount&#39;, &#39;shandongProvincialRemoteWorkshopMemberPassedCount&#39;, &#39;shandongProvincialRemoteWorkshopMemberNotPassedCount&#39;, &#39;shandongProvincialRemoteWorkshopMemberPendingCount&#39;, &#39;shandongCityRemoteWorkshopHostSumCount&#39;, &#39;shandongCityRemoteWorkshopHostPassedCount&#39;, &#39;shandongCityRemoteWorkshopHostNotPassedCount&#39;, &#39;shandongCityRemoteWorkshopHostPendingCount&#39;, &#39;shandongCityRemoteWorkshopMemberSumCount&#39;, &#39;shandongCityRemoteWorkshopMemberPassedCount&#39;, &#39;shandongCityRemoteWorkshopMemberNotPassedCount&#39;, &#39;shandongCityRemoteWorkshopMemberPendingCount&#39;, &#39;shandongCountyRemoteWorkshopHostSumCount&#39;, &#39;shandongCountyRemoteWorkshopHostPassedCount&#39;, &#39;shandongCountyRemoteWorkshopHostNotPassedCount&#39;, &#39;shandongCountyRemoteWorkshopHostPendingCount&#39;, &#39;shandongCountyRemoteWorkshopMemberSumCount&#39;, &#39;shandongCountyRemoteWorkshopMemberPassedCount&#39;, &#39;shandongCountyRemoteWorkshopMemberNotPassedCount&#39;, &#39;shandongCountyRemoteWorkshopMemberPendingCount&#39;, &#39;countryTeacherSumCount&#39;, &#39;countryTeacherPassedCount&#39;, &#39;countryTeacherNotPassedCount&#39;, &#39;countryTeacherPendingCount&#39;, &#39;ruralTeacherSumCount&#39;, &#39;ruralTeacherPassedCount&#39;, &#39;ruralTeacherNotPassedCount&#39;, &#39;ruralTeacherPendingCount&#39;, &#39;nationalOutstandingRuralYoungTeacherSumCount&#39;, &#39;nationalOutstandingRuralYoungTeacherPassedCount&#39;, &#39;nationalOutstandingRuralYoungTeacherNotPassedCount&#39;, &#39;nationalOutstandingRuralYoungTeacherPendingCount&#39;, &#39;shandongOutstandingRuralYoungTeacherSumCount&#39;, &#39;shandongOutstandingRuralYoungTeacherPassedCount&#39;, &#39;shandongOutstandingRuralYoungTeacherNotPassedCount&#39;, &#39;shandongOutstandingRuralYoungTeacherPendingCount&#39;, &#39;shandongRuralSpecialTeacherSumCount&#39;, &#39;shandongRuralSpecialTeacherPassedCount&#39;, &#39;shandongRuralSpecialTeacherNotPassedCount&#39;, &#39;shandongRuralSpecialTeacherPendingCount&#39;, &#39;professionalDevelopmentTeacherSumCount&#39;, &#39;professionalDevelopmentTeacherPassedCount&#39;, &#39;professionalDevelopmentTeacherNotPassedCount&#39;, &#39;professionalDevelopmentTeacherPendingCount&#39;, &#39;nationalTrainingExpertSumCount&#39;, &#39;nationalTrainingExpertPassedCount&#39;, &#39;nationalTrainingExpertNotPassedCount&#39;, &#39;nationalTrainingExpertPendingCount&#39;, &#39;provincialTrainingExpertSumCount&#39;, &#39;provincialTrainingExpertPassedCount&#39;, &#39;provincialTrainingExpertNotPassedCount&#39;, &#39;provincialTrainingExpertPendingCount&#39;, &#39;cityTrainingExpertSumCount&#39;, &#39;cityTrainingExpertPassedCount&#39;, &#39;cityTrainingExpertNotPassedCount&#39;, &#39;cityTrainingExpertPendingCount&#39; ], -- 值数组 [ -- 新教师总览 countIf(typeId LIKE &#39;/51_1/%&#39;), countIf(typeId LIKE &#39;/51_1/%&#39; AND approveState = &#39;pass&#39;), countIf(typeId LIKE &#39;/51_1/%&#39; AND approveState = &#39;fail&#39;), countIf(typeId LIKE &#39;/51_1/%&#39; AND approveState = &#39;wait&#39;), -- 教育教学团队总览 countIf(typeId LIKE &#39;/51_2/%&#39;), countIf(typeId LIKE &#39;/51_2/%&#39; AND approveState = &#39;pass&#39;), countIf(typeId LIKE &#39;/51_2/%&#39; AND approveState = &#39;fail&#39;), countIf(typeId LIKE &#39;/51_2/%&#39; AND approveState = &#39;wait&#39;), -- 青年教师基本功比武 countIf(typeId = &#39;/51_2/52_201/&#39;), countIf(typeId = &#39;/51_2/52_201/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_201/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_201/&#39; AND approveState = &#39;wait&#39;), -- 优质课比赛 countIf(typeId = &#39;/51_2/52_202/&#39;), countIf(typeId = &#39;/51_2/52_202/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_202/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_202/&#39; AND approveState = &#39;wait&#39;), -- 教学能手 countIf(typeId = &#39;/51_2/52_203/&#39;), countIf(typeId = &#39;/51_2/52_203/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_203/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_203/&#39; AND approveState = &#39;wait&#39;), -- 学科带头人 countIf(typeId = &#39;/51_2/52_204/&#39;), countIf(typeId = &#39;/51_2/52_204/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_204/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_204/&#39; AND approveState = &#39;wait&#39;), -- 青岛名师培养人选 countIf(typeId = &#39;/51_2/52_205/&#39;), countIf(typeId = &#39;/51_2/52_205/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_205/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_205/&#39; AND approveState = &#39;wait&#39;), -- 青岛名师 countIf(typeId = &#39;/51_2/52_206/&#39;), countIf(typeId = &#39;/51_2/52_206/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_206/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_206/&#39; AND approveState = &#39;wait&#39;), -- 终身青岛名师 countIf(typeId = &#39;/51_2/52_207/&#39;), countIf(typeId = &#39;/51_2/52_207/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_207/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_207/&#39; AND approveState = &#39;wait&#39;), -- 青岛名班主任 countIf(typeId = &#39;/51_2/52_208/&#39;), countIf(typeId = &#39;/51_2/52_208/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_208/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_208/&#39; AND approveState = &#39;wait&#39;), -- 终身青岛名班主任 countIf(typeId = &#39;/51_2/52_209/&#39;), countIf(typeId = &#39;/51_2/52_209/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_209/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_209/&#39; AND approveState = &#39;wait&#39;), -- 青岛名校长 countIf(typeId = &#39;/51_2/52_210/&#39;), countIf(typeId = &#39;/51_2/52_210/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_210/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_210/&#39; AND approveState = &#39;wait&#39;), -- 终身青岛名校长 countIf(typeId = &#39;/51_2/52_211/&#39;), countIf(typeId = &#39;/51_2/52_211/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_211/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_211/&#39; AND approveState = &#39;wait&#39;), -- 省特级教师 countIf(typeId = &#39;/51_2/52_212/&#39;), countIf(typeId = &#39;/51_2/52_212/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_212/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_212/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名师培养人选 countIf(typeId = &#39;/51_2/52_213/&#39;), countIf(typeId = &#39;/51_2/52_213/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_213/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_213/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名师 countIf(typeId = &#39;/51_2/52_214/&#39;), countIf(typeId = &#39;/51_2/52_214/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_214/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_214/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名校长培养人选 countIf(typeId = &#39;/51_2/52_215/&#39;), countIf(typeId = &#39;/51_2/52_215/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_215/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_215/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名校长 countIf(typeId = &#39;/51_2/52_216/&#39;), countIf(typeId = &#39;/51_2/52_216/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_216/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_216/&#39; AND approveState = &#39;wait&#39;), -- 国家教学名师 countIf(typeId = &#39;/51_2/52_217/&#39;), countIf(typeId = &#39;/51_2/52_217/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_2/52_217/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_2/52_217/&#39; AND approveState = &#39;wait&#39;), -- 教师发展阶段总览 countIf(typeId LIKE &#39;/51_3/%&#39;), countIf(typeId LIKE &#39;/51_3/%&#39; AND approveState = &#39;pass&#39;), countIf(typeId LIKE &#39;/51_3/%&#39; AND approveState = &#39;fail&#39;), countIf(typeId LIKE &#39;/51_3/%&#39; AND approveState = &#39;wait&#39;), -- 青岛名师工作室主持人 countIf(typeId = &#39;/51_3/52_301/&#39;), countIf(typeId = &#39;/51_3/52_301/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_301/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_301/&#39; AND approveState = &#39;wait&#39;), -- 青岛名师工作室成员 countIf(typeId = &#39;/51_3/52_302/&#39;), countIf(typeId = &#39;/51_3/52_302/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_302/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_302/&#39; AND approveState = &#39;wait&#39;), -- 青岛名班主任工作室主持人 countIf(typeId = &#39;/51_3/52_303/&#39;), countIf(typeId = &#39;/51_3/52_303/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_303/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_303/&#39; AND approveState = &#39;wait&#39;), -- 青岛名班主任工作室成员 countIf(typeId = &#39;/51_3/52_304/&#39;), countIf(typeId = &#39;/51_3/52_304/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_304/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_304/&#39; AND approveState = &#39;wait&#39;), -- 青岛名校长工作室主持人 countIf(typeId = &#39;/51_3/52_305/&#39;), countIf(typeId = &#39;/51_3/52_305/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_305/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_305/&#39; AND approveState = &#39;wait&#39;), -- 青岛名校长工作室成员 countIf(typeId = &#39;/51_3/52_306/&#39;), countIf(typeId = &#39;/51_3/52_306/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_306/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_306/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名师领航工作室主持人 countIf(typeId = &#39;/51_3/52_307/&#39;), countIf(typeId = &#39;/51_3/52_307/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_307/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_307/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名师领航工作室成员 countIf(typeId = &#39;/51_3/52_308/&#39;), countIf(typeId = &#39;/51_3/52_308/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_308/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_308/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名校长工作室主持人 countIf(typeId = &#39;/51_3/52_309/&#39;), countIf(typeId = &#39;/51_3/52_309/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_309/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_309/&#39; AND approveState = &#39;wait&#39;), -- 齐鲁名校长工作室成员 countIf(typeId = &#39;/51_3/52_310/&#39;), countIf(typeId = &#39;/51_3/52_310/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_310/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_310/&#39; AND approveState = &#39;wait&#39;), -- 山东省职教名师工作室主持人 countIf(typeId = &#39;/51_3/52_311/&#39;), countIf(typeId = &#39;/51_3/52_311/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_311/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_311/&#39; AND approveState = &#39;wait&#39;), -- 山东省职教名师工作室成员 countIf(typeId = &#39;/51_3/52_312/&#39;), countIf(typeId = &#39;/51_3/52_312/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_312/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_312/&#39; AND approveState = &#39;wait&#39;), -- 山东省职教技艺技能平台支持人 countIf(typeId = &#39;/51_3/52_313/&#39;), countIf(typeId = &#39;/51_3/52_313/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_313/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_313/&#39; AND approveState = &#39;wait&#39;), -- 山东省职教技艺技能平台成员 countIf(typeId = &#39;/51_3/52_314/&#39;), countIf(typeId = &#39;/51_3/52_314/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_314/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_314/&#39; AND approveState = &#39;wait&#39;), -- 省特级教师工作坊主持人 countIf(typeId = &#39;/51_3/52_315/&#39;), countIf(typeId = &#39;/51_3/52_315/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_315/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_315/&#39; AND approveState = &#39;wait&#39;), -- 省特级教师工作坊成员 countIf(typeId = &#39;/51_3/52_316/&#39;), countIf(typeId = &#39;/51_3/52_316/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_316/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_316/&#39; AND approveState = &#39;wait&#39;), -- 省特级教师工作坊成员群组成员 countIf(typeId = &#39;/51_3/52_317/&#39;), countIf(typeId = &#39;/51_3/52_317/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_317/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_317/&#39; AND approveState = &#39;wait&#39;), -- 山东省远程研修省级工作坊主持人 countIf(typeId = &#39;/51_3/52_318/&#39;), countIf(typeId = &#39;/51_3/52_318/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_318/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_318/&#39; AND approveState = &#39;wait&#39;), -- 山东省远程研修省级工作坊成员 countIf(typeId = &#39;/51_3/52_319/&#39;), countIf(typeId = &#39;/51_3/52_319/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_319/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_319/&#39; AND approveState = &#39;wait&#39;), -- 山东省远程研修市级工作坊主持人 countIf(typeId = &#39;/51_3/52_320/&#39;), countIf(typeId = &#39;/51_3/52_320/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_320/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_320/&#39; AND approveState = &#39;wait&#39;), -- 山东省远程研修市级工作坊成员 countIf(typeId = &#39;/51_3/52_321/&#39;), countIf(typeId = &#39;/51_3/52_321/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_321/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_321/&#39; AND approveState = &#39;wait&#39;), -- 山东省远程研修县级工作坊主持人 countIf(typeId = &#39;/51_3/52_322/&#39;), countIf(typeId = &#39;/51_3/52_322/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_322/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_322/&#39; AND approveState = &#39;wait&#39;), -- 山东省远程研修县级工作坊成员 countIf(typeId = &#39;/51_3/52_323/&#39;), countIf(typeId = &#39;/51_3/52_323/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_3/52_323/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_3/52_323/&#39; AND approveState = &#39;wait&#39;), -- 乡村教师总览 countIf(typeId LIKE &#39;/51_4/%&#39;), countIf(typeId LIKE &#39;/51_4/%&#39; AND approveState = &#39;pass&#39;), countIf(typeId LIKE &#39;/51_4/%&#39; AND approveState = &#39;fail&#39;), countIf(typeId LIKE &#39;/51_4/%&#39; AND approveState = &#39;wait&#39;), -- 乡村教师 countIf(typeId = &#39;/51_4/52_401/&#39;), countIf(typeId = &#39;/51_4/52_401/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_4/52_401/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_4/52_401/&#39; AND approveState = &#39;wait&#39;), -- 全国乡村优秀青年教师 countIf(typeId = &#39;/51_4/52_402/&#39;), countIf(typeId = &#39;/51_4/52_402/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_4/52_402/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_4/52_402/&#39; AND approveState = &#39;wait&#39;), -- 山东省乡村青年优秀教师 countIf(typeId = &#39;/51_4/52_403/&#39;), countIf(typeId = &#39;/51_4/52_403/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_4/52_403/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_4/52_403/&#39; AND approveState = &#39;wait&#39;), -- 山东省农村特级教师 countIf(typeId = &#39;/51_4/52_404/&#39;), countIf(typeId = &#39;/51_4/52_404/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_4/52_404/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_4/52_404/&#39; AND approveState = &#39;wait&#39;), -- 教师专业发展总览 countIf(typeId LIKE &#39;/51_5/%&#39;), countIf(typeId LIKE &#39;/51_5/%&#39; AND approveState = &#39;pass&#39;), countIf(typeId LIKE &#39;/51_5/%&#39; AND approveState = &#39;fail&#39;), countIf(typeId LIKE &#39;/51_5/%&#39; AND approveState = &#39;wait&#39;), -- 国培专家 countIf(typeId = &#39;/51_5/52_501/&#39;), countIf(typeId = &#39;/51_5/52_501/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_5/52_501/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_5/52_501/&#39; AND approveState = &#39;wait&#39;), -- 省培专家 countIf(typeId = &#39;/51_5/52_502/&#39;), countIf(typeId = &#39;/51_5/52_502/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_5/52_502/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_5/52_502/&#39; AND approveState = &#39;wait&#39;), -- 市培专家 countIf(typeId = &#39;/51_5/52_503/&#39;), countIf(typeId = &#39;/51_5/52_503/&#39; AND approveState = &#39;pass&#39;), countIf(typeId = &#39;/51_5/52_503/&#39; AND approveState = &#39;fail&#39;), countIf(typeId = &#39;/51_5/52_503/&#39; AND approveState = &#39;wait&#39;) ] ) AS metrics_array FROM big_data_qte_1.ads_teacher_growth FINAL GROUP BY GROUPING SETS ( (teacherProvinceId), (teacherCityId), (teacherCountyId), (teacherSchoolId) ) ) -- 步骤2:在外部查询中展开数组并插入 SELECT -- 使用内部计算好的 grouping 结果 CASE WHEN g_province = 0 THEN teacherProvinceId WHEN g_city = 0 THEN teacherCityId WHEN g_county = 0 THEN teacherCountyId WHEN g_school = 0 THEN teacherSchoolId ELSE NULL END AS regionId, &#39;_all&#39; AS stageId, &#39;_all&#39; AS subjectId, &#39;_all&#39;, -1, now(), &#39;excellent&#39;, -- 步骤3:从展开的数组中获取指标名和指标值 metrics.1 AS auditStatus, metrics.2 AS total FROM AggGrowthData ARRAY JOIN metrics_array AS metrics; 给我解释代码
11-13
from flask import Flask, render_template, request, redirect, url_for, flash, jsonify, session from werkzeug.security import generate_password_hash, check_password_hash import pymysql import uuid from datetime import datetime, timedelta from functools import wraps app = Flask(__name__) app.config[&#39;SECRET_KEY&#39;] = &#39;your-secret-key-change-in-production&#39; # 数据库配置 - 请根据您的实际情况修改 DB_CONFIG = { &#39;host&#39;: &#39;localhost&#39;, &#39;user&#39;: &#39;root&#39;, &#39;password&#39;: &#39;lufei666666&#39;, &#39;database&#39;: &#39;student_course_system&#39;, &#39;charset&#39;: &#39;utf8mb4&#39; } def get_db_connection(): """获取数据库连接""" return pymysql.connect(**DB_CONFIG) def execute_query(query, params=None, fetch=True): """执行SQL查询""" conn = get_db_connection() cursor = conn.cursor(pymysql.cursors.DictCursor) try: cursor.execute(query, params) if fetch: if query.strip().upper().startswith(&#39;SELECT&#39;): result = cursor.fetchall() else: conn.commit() result = cursor.lastrowid else: conn.commit() result = None return result except Exception as e: conn.rollback() raise e finally: cursor.close() conn.close() def login_required(role=None): """登录装饰器""" def decorator(f): @wraps(f) def decorated_function(*args, **kwargs): if &#39;user_id&#39; not in session: flash(&#39;请先登录!&#39;, &#39;error&#39;) return redirect(url_for(&#39;login&#39;)) if role and session.get(&#39;role&#39;) != role: flash(&#39;无权访问此页面!&#39;, &#39;error&#39;) return redirect(url_for(&#39;index&#39;)) return f(*args, **kwargs) return decorated_function return decorator # ========== 通用路由 ========== @app.route(&#39;/&#39;) def index(): return render_template(&#39;index.html&#39;) @app.route(&#39;/login&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;]) def login(): if request.method == &#39;POST&#39;: username = request.form.get(&#39;username&#39;) password = request.form.get(&#39;password&#39;) try: users = execute_query( "SELECT * FROM user WHERE username = %s", (username,) ) if users and check_password_hash(users[0][&#39;password&#39;], password): session[&#39;user_id&#39;] = users[0][&#39;id&#39;] session[&#39;username&#39;] = users[0][&#39;username&#39;] session[&#39;role&#39;] = users[0][&#39;role&#39;] flash(&#39;登录成功!&#39;, &#39;success&#39;) if users[0][&#39;role&#39;] == &#39;admin&#39;: return redirect(url_for(&#39;admin_dashboard&#39;)) elif users[0][&#39;role&#39;] == &#39;teacher&#39;: return redirect(url_for(&#39;teacher_dashboard&#39;)) else: return redirect(url_for(&#39;student_dashboard&#39;)) else: flash(&#39;用户名或密码错误!&#39;, &#39;error&#39;) except Exception as e: flash(f&#39;登录失败: {str(e)}&#39;, &#39;error&#39;) return render_template(&#39;login.html&#39;) @app.route(&#39;/logout&#39;) def logout(): session.clear() flash(&#39;您已成功退出系统!&#39;, &#39;success&#39;) return redirect(url_for(&#39;index&#39;)) # ========== 管理员路由 ========== @app.route(&#39;/admin/dashboard&#39;) @login_required(role=&#39;admin&#39;) def admin_dashboard(): try: student_count = execute_query("SELECT COUNT(*) as count FROM student")[0][&#39;count&#39;] teacher_count = execute_query("SELECT COUNT(*) as count FROM teacher")[0][&#39;count&#39;] course_count = execute_query("SELECT COUNT(*) as count FROM course")[0][&#39;count&#39;] classroom_count = execute_query("SELECT COUNT(*) as count FROM classroom")[0][&#39;count&#39;] return render_template(&#39;admin/dashboard.html&#39;, student_count=student_count, teacher_count=teacher_count, course_count=course_count, classroom_count=classroom_count) except Exception as e: flash(f&#39;加载仪表板失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;index&#39;)) # ========== 院系管理 ========== @app.route(&#39;/admin/yuanxi&#39;) @login_required(role=&#39;admin&#39;) def admin_yuanxi(): try: yuanxi_list = execute_query("SELECT * FROM yuanxi ORDER BY create_time DESC") return render_template(&#39;admin/yuanxi.html&#39;, yuanxi_list=yuanxi_list) except Exception as e: flash(f&#39;加载院系列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/yuanxi/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_yuanxi(): yuanxi_name = request.form.get(&#39;yuanxi_name&#39;) yuanxi_desc = request.form.get(&#39;yuanxi_desc&#39;) try: execute_query( "INSERT INTO yuanxi (yuanxi_name, yuanxi_desc) VALUES (%s, %s)", (yuanxi_name, yuanxi_desc), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;院系添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) @app.route(&#39;/admin/yuanxi/<int:id>/delete&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def delete_yuanxi(id): try: execute_query( "DELETE FROM yuanxi WHERE id = %s", (id,), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;院系删除成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;删除失败: {str(e)}&#39;}) # ========== 班级管理 ========== @app.route(&#39;/admin/banji&#39;) @login_required(role=&#39;admin&#39;) def admin_banji(): try: banji_list = execute_query(""" SELECT b.*, y.yuanxi_name FROM banji b LEFT JOIN yuanxi y ON b.yuanxi_id = y.id ORDER BY b.create_time DESC """) yuanxi_list = execute_query("SELECT * FROM yuanxi ORDER BY yuanxi_name") return render_template(&#39;admin/banji.html&#39;, banji_list=banji_list, yuanxi_list=yuanxi_list) except Exception as e: flash(f&#39;加载班级列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/banji/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_banji(): banji_name = request.form.get(&#39;banji_name&#39;) yuanxi_id = request.form.get(&#39;yuanxi_id&#39;) banji_desc = request.form.get(&#39;banji_desc&#39;) try: execute_query( "INSERT INTO banji (banji_name, yuanxi_id, banji_desc) VALUES (%s, %s, %s)", (banji_name, yuanxi_id, banji_desc), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;班级添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) @app.route(&#39;/admin/banji/<int:id>/delete&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def delete_banji(id): try: execute_query( "DELETE FROM banji WHERE id = %s", (id,), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;班级删除成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;删除失败: {str(e)}&#39;}) # ========== 课程性质管理 ========== @app.route(&#39;/admin/kecheng_xingzhi&#39;) @login_required(role=&#39;admin&#39;) def admin_kecheng_xingzhi(): try: xingzhi_list = execute_query("SELECT * FROM kecheng_xingzhi ORDER BY create_time DESC") return render_template(&#39;admin/kecheng_xingzhi.html&#39;, xingzhi_list=xingzhi_list) except Exception as e: flash(f&#39;加载课程性质列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/kecheng_xingzhi/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_kecheng_xingzhi(): xingzhi_name = request.form.get(&#39;xingzhi_name&#39;) xingzhi_desc = request.form.get(&#39;xingzhi_desc&#39;) try: execute_query( "INSERT INTO kecheng_xingzhi (xingzhi_name, xingzhi_desc) VALUES (%s, %s)", (xingzhi_name, xingzhi_desc), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;课程性质添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) @app.route(&#39;/admin/kecheng_xingzhi/<int:id>/delete&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def delete_kecheng_xingzhi(id): try: execute_query( "DELETE FROM kecheng_xingzhi WHERE id = %s", (id,), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;课程性质删除成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;删除失败: {str(e)}&#39;}) # ========== 计划类型管理 ========== @app.route(&#39;/admin/jihua_types&#39;) @login_required(role=&#39;admin&#39;) def admin_jihua_types(): try: jihua_types_list = execute_query("SELECT * FROM jihua_types ORDER BY create_time DESC") return render_template(&#39;admin/jihua_types.html&#39;, jihua_types_list=jihua_types_list) except Exception as e: flash(f&#39;加载计划类型列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/jihua_types/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_jihua_types(): type_name = request.form.get(&#39;type_name&#39;) type_desc = request.form.get(&#39;type_desc&#39;) try: execute_query( "INSERT INTO jihua_types (type_name, type_desc) VALUES (%s, %s)", (type_name, type_desc), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;计划类型添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) @app.route(&#39;/admin/jihua_types/<int:id>/delete&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def delete_jihua_types(id): try: execute_query( "DELETE FROM jihua_types WHERE id = %s", (id,), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;计划类型删除成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;删除失败: {str(e)}&#39;}) # ========== 学生管理 ========== @app.route(&#39;/admin/students&#39;) @login_required(role=&#39;admin&#39;) def admin_students(): try: students = execute_query(""" SELECT s.*, u.username, b.banji_name, y.yuanxi_name FROM student s JOIN user u ON s.user_id = u.id LEFT JOIN banji b ON s.banji_types = b.id LEFT JOIN yuanxi y ON b.yuanxi_id = y.id ORDER BY s.create_time DESC """) banji_list = execute_query("SELECT * FROM banji ORDER BY banji_name") return render_template(&#39;admin/students.html&#39;, students=students, banji_list=banji_list) except Exception as e: flash(f&#39;加载学生列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/student/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_student(): username = request.form.get(&#39;username&#39;) password = request.form.get(&#39;password&#39;) student_name = request.form.get(&#39;student_name&#39;) student_phone = request.form.get(&#39;student_phone&#39;) student_email = request.form.get(&#39;student_email&#39;) sex_types = request.form.get(&#39;sex_types&#39;) banji_types = request.form.get(&#39;banji_types&#39;) try: execute_query( "INSERT INTO user (username, password, role) VALUES (%s, %s, %s)", (username, generate_password_hash(password), &#39;student&#39;), fetch=False ) user_id = execute_query("SELECT LAST_INSERT_ID() as id")[0][&#39;id&#39;] execute_query( "INSERT INTO student (user_id, student_name, student_phone, student_email, sex_types, banji_types) VALUES (%s, %s, %s, %s, %s, %s)", (user_id, student_name, student_phone, student_email, sex_types, banji_types), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;学生添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) # ========== 教师管理 ========== @app.route(&#39;/admin/teachers&#39;) @login_required(role=&#39;admin&#39;) def admin_teachers(): try: teachers = execute_query(""" SELECT t.*, u.username FROM teacher t JOIN user u ON t.user_id = u.id ORDER BY t.create_time DESC """) return render_template(&#39;admin/teachers.html&#39;, teachers=teachers) except Exception as e: flash(f&#39;加载教师列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/teacher/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_teacher(): username = request.form.get(&#39;username&#39;) password = request.form.get(&#39;password&#39;) teacher_name = request.form.get(&#39;teacher_name&#39;) teacher_phone = request.form.get(&#39;teacher_phone&#39;) teacher_email = request.form.get(&#39;teacher_email&#39;) sex_types = request.form.get(&#39;sex_types&#39;) teacher_shanchang = request.form.get(&#39;teacher_shanchang&#39;) teacher_rongyu = request.form.get(&#39;teacher_rongyu&#39;) teacher_content = request.form.get(&#39;teacher_content&#39;) try: execute_query( "INSERT INTO user (username, password, role) VALUES (%s, %s, %s)", (username, generate_password_hash(password), &#39;teacher&#39;), fetch=False ) user_id = execute_query("SELECT LAST_INSERT_ID() as id")[0][&#39;id&#39;] execute_query( """INSERT INTO teacher (user_id, teacher_name, teacher_phone, teacher_email, sex_types, teacher_shanchang, teacher_rongyu, teacher_content) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)""", (user_id, teacher_name, teacher_phone, teacher_email, sex_types, teacher_shanchang, teacher_rongyu, teacher_content), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;教师添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) # ========== 课程管理 ========== @app.route(&#39;/admin/courses&#39;) @login_required(role=&#39;admin&#39;) def admin_courses(): try: courses = execute_query(""" SELECT c.*, t.teacher_name, y.yuanxi_name, kx.xingzhi_name, kt.kaohe_name, (SELECT COUNT(*) FROM course_selection WHERE course_id = c.id) as selected_count FROM course c JOIN teacher t ON c.teacher_id = t.id LEFT JOIN yuanxi y ON c.yuanxi_types = y.id LEFT JOIN kecheng_xingzhi kx ON c.course_xingzhi_types = kx.id LEFT JOIN kaohe_types kt ON c.course_kaohe_types = kt.id ORDER BY c.create_time DESC """) teachers = execute_query("SELECT * FROM teacher ORDER BY teacher_name") yuanxi_list = execute_query("SELECT * FROM yuanxi ORDER BY yuanxi_name") xingzhi_list = execute_query("SELECT * FROM kecheng_xingzhi ORDER BY xingzhi_name") kaohe_list = execute_query("SELECT * FROM kaohe_types ORDER BY kaohe_name") return render_template(&#39;admin/courses.html&#39;, courses=courses, teachers=teachers, yuanxi_list=yuanxi_list, xingzhi_list=xingzhi_list, kaohe_list=kaohe_list, total_students=len(courses), now=datetime.now()) except Exception as e: flash(f&#39;加载课程列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/course/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_course(): teacher_id = request.form.get(&#39;teacher_id&#39;) course_name = request.form.get(&#39;course_name&#39;) course_daima = request.form.get(&#39;course_daima&#39;) yuanxi_types = request.form.get(&#39;yuanxi_types&#39;) course_xingzhi_types = request.form.get(&#39;course_xingzhi_types&#39;) course_xuefen = request.form.get(&#39;course_xuefen&#39;) course_zongxueshi = request.form.get(&#39;course_zongxueshi&#39;) course_kaohe_types = request.form.get(&#39;course_kaohe_types&#39;) course_renshu = request.form.get(&#39;course_renshu&#39;) jiezhi_time = request.form.get(&#39;jiezhi_time&#39;) course_content = request.form.get(&#39;course_content&#39;) try: execute_query( """INSERT INTO course (teacher_id, course_uuid_number, course_name, course_daima, yuanxi_types, course_xingzhi_types, course_xuefen, course_zongxueshi, course_kaohe_types, course_renshu, jiezhi_time, course_content) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", (teacher_id, str(uuid.uuid4()), course_name, course_daima, yuanxi_types, course_xingzhi_types, course_xuefen, course_zongxueshi, course_kaohe_types, course_renshu, jiezhi_time, course_content), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;课程添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) # ========== 教学计划管理 ========== @app.route(&#39;/admin/teaching_plans&#39;) @login_required(role=&#39;admin&#39;) def admin_teaching_plans(): try: teaching_plans = execute_query(""" SELECT tp.*, c.course_name, jt.type_name FROM teaching_plan tp JOIN course c ON tp.course_id = c.id LEFT JOIN jihua_types jt ON tp.teaching_plan_types = jt.id ORDER BY tp.create_time DESC """) courses = execute_query("SELECT * FROM course ORDER BY course_name") jihua_types_list = execute_query("SELECT * FROM jihua_types ORDER BY type_name") return render_template(&#39;admin/teaching_plans.html&#39;, teaching_plans=teaching_plans, courses=courses, jihua_types_list=jihua_types_list) except Exception as e: flash(f&#39;加载教学计划列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/teaching_plan/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_teaching_plan(): course_id = request.form.get(&#39;course_id&#39;) teaching_plan_name = request.form.get(&#39;teaching_plan_name&#39;) teaching_plan_types = request.form.get(&#39;teaching_plan_types&#39;) teaching_plan_content = request.form.get(&#39;teaching_plan_content&#39;) try: execute_query( """INSERT INTO teaching_plan (course_id, teaching_plan_uuid_number, teaching_plan_name, teaching_plan_types, teaching_plan_content) VALUES (%s, %s, %s, %s, %s)""", (course_id, str(uuid.uuid4()), teaching_plan_name, teaching_plan_types, teaching_plan_content), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;教学计划添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) # ========== 选课管理 ========== @app.route(&#39;/admin/course_selections&#39;) @login_required(role=&#39;admin&#39;) def admin_course_selections(): try: course_selections = execute_query(""" SELECT cs.*, s.student_name, c.course_name, t.teacher_name FROM course_selection cs JOIN student s ON cs.student_id = s.id JOIN course c ON cs.course_id = c.id JOIN teacher t ON c.teacher_id = t.id ORDER BY cs.create_time DESC """) students = execute_query("SELECT * FROM student ORDER BY student_name") courses = execute_query("SELECT * FROM course ORDER BY course_name") return render_template(&#39;admin/course_selections.html&#39;, course_selections=course_selections, students=students, courses=courses) except Exception as e: flash(f&#39;加载选课列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/course_selection/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_course_selection(): student_id = request.form.get(&#39;student_id&#39;) course_id = request.form.get(&#39;course_id&#39;) try: # 检查是否已经选过该课程 existing = execute_query( "SELECT * FROM course_selection WHERE student_id = %s AND course_id = %s", (student_id, course_id) ) if existing: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;该学生已经选择了此课程!&#39;}) # 检查课程人数限制 course = execute_query("SELECT * FROM course WHERE id = %s", (course_id,))[0] current_count = execute_query( "SELECT COUNT(*) as count FROM course_selection WHERE course_id = %s", (course_id,) )[0][&#39;count&#39;] if current_count >= course[&#39;course_renshu&#39;]: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;该课程已满!&#39;}) execute_query( "INSERT INTO course_selection (student_id, course_id, selection_uuid_number) VALUES (%s, %s, %s)", (student_id, course_id, str(uuid.uuid4())), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;选课添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) @app.route(&#39;/admin/course_selection/<int:id>/delete&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def delete_course_selection(id): try: execute_query( "DELETE FROM course_selection WHERE id = %s", (id,), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;选课记录删除成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;删除失败: {str(e)}&#39;}) # ========== 成绩管理 ========== @app.route(&#39;/admin/grades&#39;) @login_required(role=&#39;admin&#39;) def admin_grades(): try: grades = execute_query(""" SELECT g.*, s.student_name, c.course_name, t.teacher_name FROM grade g JOIN student s ON g.student_id = s.id JOIN course c ON g.course_id = c.id JOIN teacher t ON c.teacher_id = t.id ORDER BY g.create_time DESC """) students = execute_query("SELECT * FROM student ORDER BY student_name") courses = execute_query("SELECT * FROM course ORDER BY course_name") return render_template(&#39;admin/grades.html&#39;, grades=grades, students=students, courses=courses) except Exception as e: flash(f&#39;加载成绩列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/grade/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_grade(): student_id = request.form.get(&#39;student_id&#39;) course_id = request.form.get(&#39;course_id&#39;) grade_score = request.form.get(&#39;grade_score&#39;) grade_comment = request.form.get(&#39;grade_comment&#39;) try: # 检查是否已经存在成绩记录 existing = execute_query( "SELECT * FROM grade WHERE student_id = %s AND course_id = %s", (student_id, course_id) ) if existing: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;该学生在此课程中已有成绩记录!&#39;}) execute_query( "INSERT INTO grade (student_id, course_id, grade_score, grade_comment, grade_uuid_number) VALUES (%s, %s, %s, %s, %s)", (student_id, course_id, grade_score, grade_comment, str(uuid.uuid4())), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;成绩添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) @app.route(&#39;/admin/grade/<int:id>/delete&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def delete_grade(id): try: execute_query( "DELETE FROM grade WHERE id = %s", (id,), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;成绩记录删除成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;删除失败: {str(e)}&#39;}) # ========== 教室管理 ========== @app.route(&#39;/admin/classrooms&#39;) @login_required(role=&#39;admin&#39;) def admin_classrooms(): try: classrooms = execute_query("SELECT * FROM classroom ORDER BY create_time DESC") return render_template(&#39;admin/classrooms.html&#39;, classrooms=classrooms) except Exception as e: flash(f&#39;加载教室列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) @app.route(&#39;/admin/classroom/add&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def add_classroom(): classroom_name = request.form.get(&#39;classroom_name&#39;) classroom_address = request.form.get(&#39;classroom_address&#39;) classroom_content = request.form.get(&#39;classroom_content&#39;) try: execute_query( "INSERT INTO classroom (classroom_uuid_number, classroom_name, classroom_address, classroom_content) VALUES (%s, %s, %s, %s)", (str(uuid.uuid4()), classroom_name, classroom_address, classroom_content), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;教室添加成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;添加失败: {str(e)}&#39;}) @app.route(&#39;/admin/classroom/<int:id>/delete&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def delete_classroom(id): try: execute_query( "DELETE FROM classroom WHERE id = %s", (id,), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;教室删除成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;删除失败: {str(e)}&#39;}) # ========== 管理员修改密码 ========== @app.route(&#39;/admin/change_password&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;]) @login_required(role=&#39;admin&#39;) def admin_change_password(): if request.method == &#39;POST&#39;: old_password = request.form.get(&#39;old_password&#39;) new_password = request.form.get(&#39;new_password&#39;) confirm_password = request.form.get(&#39;confirm_password&#39;) if new_password != confirm_password: flash(&#39;新密码和确认密码不一致!&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_change_password&#39;)) try: user = execute_query("SELECT * FROM user WHERE id = %s", (session[&#39;user_id&#39;],))[0] if not check_password_hash(user[&#39;password&#39;], old_password): flash(&#39;旧密码错误!&#39;, &#39;error&#39;) return redirect(url_for(&#39;admin_change_password&#39;)) execute_query( "UPDATE user SET password = %s WHERE id = %s", (generate_password_hash(new_password), session[&#39;user_id&#39;]), fetch=False ) flash(&#39;密码修改成功!&#39;, &#39;success&#39;) return redirect(url_for(&#39;admin_dashboard&#39;)) except Exception as e: flash(f&#39;密码修改失败: {str(e)}&#39;, &#39;error&#39;) return render_template(&#39;admin/change_password.html&#39;) # ========== 教师路由 ========== @app.route(&#39;/teacher/dashboard&#39;) @login_required(role=&#39;teacher&#39;) def teacher_dashboard(): try: user_id = session[&#39;user_id&#39;] teachers = execute_query( "SELECT * FROM teacher WHERE user_id = %s", (user_id,) ) if not teachers: flash(&#39;教师信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;index&#39;)) teacher = teachers[0] courses = execute_query( "SELECT * FROM course WHERE teacher_id = %s", (teacher[&#39;id&#39;],) ) total_students = execute_query(""" SELECT COUNT(DISTINCT cs.student_id) as count FROM course_selection cs JOIN course c ON cs.course_id = c.id WHERE c.teacher_id = %s """, (teacher[&#39;id&#39;],))[0][&#39;count&#39;] teaching_plans_count = execute_query(""" SELECT COUNT(*) as count FROM teaching_plan tp JOIN course c ON tp.course_id = c.id WHERE c.teacher_id = %s """, (teacher[&#39;id&#39;],))[0][&#39;count&#39;] grades_count = execute_query(""" SELECT COUNT(*) as count FROM grade g JOIN course c ON g.course_id = c.id WHERE c.teacher_id = %s """, (teacher[&#39;id&#39;],))[0][&#39;count&#39;] pending_grades_count = execute_query(""" SELECT COUNT(DISTINCT cs.student_id) as count FROM course_selection cs JOIN course c ON cs.course_id = c.id LEFT JOIN grade g ON g.student_id = cs.student_id AND g.course_id = cs.course_id WHERE c.teacher_id = %s AND g.id IS NULL """, (teacher[&#39;id&#39;],))[0][&#39;count&#39;] upcoming_deadlines = execute_query(""" SELECT * FROM course WHERE teacher_id = %s AND jiezhi_time > %s AND jiezhi_time < %s """, (teacher[&#39;id&#39;], datetime.now(), datetime.now() + timedelta(days=7))) return render_template(&#39;teacher/dashboard.html&#39;, teacher=teacher, courses=courses, total_students=total_students, teaching_plans_count=teaching_plans_count, grades_count=grades_count, pending_grades_count=pending_grades_count, upcoming_deadlines=upcoming_deadlines, now=datetime.now()) except Exception as e: flash(f&#39;加载教师仪表板失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;index&#39;)) @app.route(&#39;/teacher/courses&#39;) @login_required(role=&#39;teacher&#39;) def teacher_courses(): try: user_id = session[&#39;user_id&#39;] teachers = execute_query( "SELECT * FROM teacher WHERE user_id = %s", (user_id,) ) if not teachers: flash(&#39;教师信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) teacher = teachers[0] courses = execute_query(""" SELECT c.*, (SELECT COUNT(*) FROM course_selection WHERE course_id = c.id) as selected_count FROM course c WHERE c.teacher_id = %s ORDER BY c.create_time DESC """, (teacher[&#39;id&#39;],)) return render_template(&#39;teacher/courses.html&#39;, courses=courses, teacher=teacher, now=datetime.now()) except Exception as e: flash(f&#39;加载课程列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) @app.route(&#39;/teacher/teaching_plans&#39;) @login_required(role=&#39;teacher&#39;) def teacher_teaching_plans(): try: user_id = session[&#39;user_id&#39;] teachers = execute_query( "SELECT * FROM teacher WHERE user_id = %s", (user_id,) ) if not teachers: flash(&#39;教师信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) teacher = teachers[0] teaching_plans = execute_query(""" SELECT tp.*, c.course_name, jt.type_name FROM teaching_plan tp JOIN course c ON tp.course_id = c.id LEFT JOIN jihua_types jt ON tp.teaching_plan_types = jt.id WHERE c.teacher_id = %s ORDER BY tp.create_time DESC """, (teacher[&#39;id&#39;],)) courses = execute_query( "SELECT id, course_name FROM course WHERE teacher_id = %s ORDER BY course_name", (teacher[&#39;id&#39;],) ) jihua_types_list = execute_query("SELECT * FROM jihua_types ORDER BY type_name") return render_template(&#39;teacher/teaching_plans.html&#39;, teaching_plans=teaching_plans, courses=courses, jihua_types_list=jihua_types_list, teacher=teacher) except Exception as e: flash(f&#39;加载教学计划失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) @app.route(&#39;/teacher/grades&#39;) @login_required(role=&#39;teacher&#39;) def teacher_grades(): try: user_id = session[&#39;user_id&#39;] teachers = execute_query( "SELECT * FROM teacher WHERE user_id = %s", (user_id,) ) if not teachers: flash(&#39;教师信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) teacher = teachers[0] grades = execute_query(""" SELECT g.*, s.student_name, c.course_name FROM grade g JOIN student s ON g.student_id = s.id JOIN course c ON g.course_id = c.id WHERE c.teacher_id = %s ORDER BY g.create_time DESC """, (teacher[&#39;id&#39;],)) courses = execute_query( "SELECT id, course_name FROM course WHERE teacher_id = %s ORDER BY course_name", (teacher[&#39;id&#39;],) ) course_selections = execute_query(""" SELECT cs.*, s.student_name, c.course_name FROM course_selection cs JOIN student s ON cs.student_id = s.id JOIN course c ON cs.course_id = c.id WHERE c.teacher_id = %s """, (teacher[&#39;id&#39;],)) return render_template(&#39;teacher/grades.html&#39;, grades=grades, courses=courses, course_selections=course_selections, teacher=teacher) except Exception as e: flash(f&#39;加载成绩列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) @app.route(&#39;/teacher/classrooms&#39;) @login_required(role=&#39;teacher&#39;) def teacher_classrooms(): try: classrooms = execute_query("SELECT * FROM classroom ORDER BY create_time DESC") return render_template(&#39;teacher/classrooms.html&#39;, classrooms=classrooms) except Exception as e: flash(f&#39;加载教室列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) @app.route(&#39;/teacher/profile&#39;) @login_required(role=&#39;teacher&#39;) def teacher_profile(): try: user_id = session[&#39;user_id&#39;] teachers = execute_query(""" SELECT t.*, u.username FROM teacher t JOIN user u ON t.user_id = u.id WHERE t.user_id = %s """, (user_id,)) if not teachers: flash(&#39;教师信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) teacher = teachers[0] return render_template(&#39;teacher/profile.html&#39;, teacher=teacher) except Exception as e: flash(f&#39;加载个人信息失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) @app.route(&#39;/teacher/change_password&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;]) @login_required(role=&#39;teacher&#39;) def teacher_change_password(): if request.method == &#39;POST&#39;: old_password = request.form.get(&#39;old_password&#39;) new_password = request.form.get(&#39;new_password&#39;) confirm_password = request.form.get(&#39;confirm_password&#39;) if new_password != confirm_password: flash(&#39;新密码和确认密码不一致!&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_change_password&#39;)) try: user = execute_query("SELECT * FROM user WHERE id = %s", (session[&#39;user_id&#39;],))[0] if not check_password_hash(user[&#39;password&#39;], old_password): flash(&#39;旧密码错误!&#39;, &#39;error&#39;) return redirect(url_for(&#39;teacher_change_password&#39;)) execute_query( "UPDATE user SET password = %s WHERE id = %s", (generate_password_hash(new_password), session[&#39;user_id&#39;]), fetch=False ) flash(&#39;密码修改成功!&#39;, &#39;success&#39;) return redirect(url_for(&#39;teacher_dashboard&#39;)) except Exception as e: flash(f&#39;密码修改失败: {str(e)}&#39;, &#39;error&#39;) return render_template(&#39;teacher/change_password.html&#39;) # ========== 学生路由 ========== @app.route(&#39;/student/dashboard&#39;) @login_required(role=&#39;student&#39;) def student_dashboard(): try: user_id = session[&#39;user_id&#39;] students = execute_query( "SELECT * FROM student WHERE user_id = %s", (user_id,) ) if not students: flash(&#39;学生信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;index&#39;)) student = students[0] # 获取学生详细信息(班级、院系) student_details = execute_query(""" SELECT s.*, b.banji_name, y.yuanxi_name FROM student s LEFT JOIN banji b ON s.banji_types = b.id LEFT JOIN yuanxi y ON b.yuanxi_id = y.id WHERE s.user_id = %s """, (user_id,))[0] # 获取已选课程 selected_courses = execute_query(""" SELECT c.*, t.teacher_name, cs.create_time as selection_time FROM course_selection cs JOIN course c ON cs.course_id = c.id JOIN teacher t ON c.teacher_id = t.id WHERE cs.student_id = %s ORDER BY cs.create_time DESC """, (student[&#39;id&#39;],)) # 获取成绩 grades = execute_query(""" SELECT g.*, c.course_name, t.teacher_name, c.course_xuefen FROM grade g JOIN course c ON g.course_id = c.id JOIN teacher t ON c.teacher_id = t.id WHERE g.student_id = %s ORDER BY g.create_time DESC """, (student[&#39;id&#39;],)) # 获取可选课程数量 available_courses = execute_query(""" SELECT COUNT(*) as count FROM course WHERE jiezhi_time > %s OR jiezhi_time IS NULL """, (datetime.now(),)) available_courses_count = available_courses[0][&#39;count&#39;] if available_courses else 0 # 最近成绩(前5个) recent_grades = grades[:5] if grades else [] return render_template(&#39;student/dashboard.html&#39;, student=student_details, selected_courses=selected_courses, grades=grades, recent_grades=recent_grades, available_courses_count=available_courses_count, now=datetime.now()) except Exception as e: flash(f&#39;加载学生仪表板失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;index&#39;)) @app.route(&#39;/student/courses&#39;) @login_required(role=&#39;student&#39;) def student_courses(): try: user_id = session[&#39;user_id&#39;] # 获取学生信息 students = execute_query( "SELECT * FROM student WHERE user_id = %s", (user_id,) ) if not students: flash(&#39;学生信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) student = students[0] # 构建查询条件 query_params = [] where_conditions = ["c.jiezhi_time > %s OR c.jiezhi_time IS NULL"] query_params.append(datetime.now()) # 课程性质筛选 course_type = request.args.get(&#39;course_type&#39;) if course_type: where_conditions.append("c.course_xingzhi_types = %s") query_params.append(course_type) # 院系筛选 department = request.args.get(&#39;department&#39;) if department: where_conditions.append("c.yuanxi_types = %s") query_params.append(department) # 搜索条件 search = request.args.get(&#39;search&#39;) if search: where_conditions.append("(c.course_name LIKE %s OR c.course_daima LIKE %s OR t.teacher_name LIKE %s)") query_params.extend([f"%{search}%", f"%{search}%", f"%{search}%"]) # 排序方式 sort_by = request.args.get(&#39;sort&#39;, &#39;new&#39;) order_by = "c.create_time DESC" if sort_by == &#39;popular&#39;: order_by = "selected_count DESC" elif sort_by == &#39;name&#39;: order_by = "c.course_name ASC" # 获取课程列表 courses = execute_query(f""" SELECT c.*, t.teacher_name, y.yuanxi_name, kx.xingzhi_name, (SELECT COUNT(*) FROM course_selection WHERE course_id = c.id) as selected_count FROM course c JOIN teacher t ON c.teacher_id = t.id LEFT JOIN yuanxi y ON c.yuanxi_types = y.id LEFT JOIN kecheng_xingzhi kx ON c.course_xingzhi_types = kx.id WHERE {&#39; AND &#39;.join(where_conditions)} ORDER BY {order_by} """, tuple(query_params)) # 获取学生已选课程ID selected_courses = execute_query( "SELECT course_id FROM course_selection WHERE student_id = %s", (student[&#39;id&#39;],) ) selected_course_ids = [sc[&#39;course_id&#39;] for sc in selected_courses] # 获取院系列表 yuanxi_list = execute_query("SELECT * FROM yuanxi ORDER BY yuanxi_name") return render_template(&#39;student/courses.html&#39;, courses=courses, selected_course_ids=selected_course_ids, yuanxi_list=yuanxi_list, now=datetime.now()) except Exception as e: flash(f&#39;加载课程列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) @app.route(&#39;/student/course/select/<int:course_id>&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;student&#39;) def student_select_course(course_id): try: user_id = session[&#39;user_id&#39;] students = execute_query( "SELECT * FROM student WHERE user_id = %s", (user_id,) ) if not students: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;学生信息不存在!&#39;}) student = students[0] # 检查是否已经选过该课程 existing_selection = execute_query( "SELECT * FROM course_selection WHERE student_id = %s AND course_id = %s", (student[&#39;id&#39;], course_id) ) if existing_selection: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;您已经选择了此课程!&#39;}) # 检查课程信息 courses = execute_query("SELECT * FROM course WHERE id = %s", (course_id,)) if not courses: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;课程不存在!&#39;}) course = courses[0] # 检查课程人数限制 current_selections = execute_query( "SELECT COUNT(*) as count FROM course_selection WHERE course_id = %s", (course_id,) )[0][&#39;count&#39;] if current_selections >= course[&#39;course_renshu&#39;]: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;该课程已满!&#39;}) # 检查选课时间 if course[&#39;jiezhi_time&#39;] and course[&#39;jiezhi_time&#39;] < datetime.now(): return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;选课时间已过!&#39;}) # 执行选课 execute_query( "INSERT INTO course_selection (student_id, course_id, selection_uuid_number) VALUES (%s, %s, %s)", (student[&#39;id&#39;], course_id, str(uuid.uuid4())), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;选课成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;选课失败: {str(e)}&#39;}) @app.route(&#39;/student/course_selections&#39;) @login_required(role=&#39;student&#39;) def student_course_selections(): try: user_id = session[&#39;user_id&#39;] students = execute_query( "SELECT * FROM student WHERE user_id = %s", (user_id,) ) if not students: flash(&#39;学生信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) student = students[0] # 获取已选课程详情 selected_courses = execute_query(""" SELECT c.*, t.teacher_name, cs.create_time as selection_time, CASE WHEN c.jiezhi_time IS NULL OR c.jiezhi_time > NOW() THEN 1 ELSE 0 END as can_withdraw FROM course_selection cs JOIN course c ON cs.course_id = c.id JOIN teacher t ON c.teacher_id = t.id WHERE cs.student_id = %s ORDER BY cs.create_time DESC """, (student[&#39;id&#39;],)) return render_template(&#39;student/course_selections.html&#39;, selected_courses=selected_courses, now=datetime.now()) except Exception as e: flash(f&#39;加载选课列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) @app.route(&#39;/student/course/withdraw/<int:course_id>&#39;, methods=[&#39;POST&#39;]) @login_required(role=&#39;student&#39;) def student_withdraw_course(course_id): try: user_id = session[&#39;user_id&#39;] students = execute_query( "SELECT * FROM student WHERE user_id = %s", (user_id,) ) if not students: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;学生信息不存在!&#39;}) student = students[0] # 检查选课记录 selection = execute_query( "SELECT * FROM course_selection WHERE student_id = %s AND course_id = %s", (student[&#39;id&#39;], course_id) ) if not selection: return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;未找到选课记录!&#39;}) # 检查课程是否允许退选(选课截止前) course = execute_query("SELECT * FROM course WHERE id = %s", (course_id,))[0] if course[&#39;jiezhi_time&#39;] and course[&#39;jiezhi_time&#39;] < datetime.now(): return jsonify({&#39;success&#39;: False, &#39;message&#39;: &#39;选课已截止,无法退选!&#39;}) # 执行退选 execute_query( "DELETE FROM course_selection WHERE student_id = %s AND course_id = %s", (student[&#39;id&#39;], course_id), fetch=False ) return jsonify({&#39;success&#39;: True, &#39;message&#39;: &#39;退选成功!&#39;}) except Exception as e: return jsonify({&#39;success&#39;: False, &#39;message&#39;: f&#39;退选失败: {str(e)}&#39;}) @app.route(&#39;/student/grades&#39;) @login_required(role=&#39;student&#39;) def student_grades(): try: user_id = session[&#39;user_id&#39;] students = execute_query( "SELECT * FROM student WHERE user_id = %s", (user_id,) ) if not students: flash(&#39;学生信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) student = students[0] # 获取成绩列表 grades = execute_query(""" SELECT g.*, c.course_name, t.teacher_name, c.course_xuefen, c.course_daima FROM grade g JOIN course c ON g.course_id = c.id JOIN teacher t ON c.teacher_id = t.id WHERE g.student_id = %s ORDER BY g.create_time DESC """, (student[&#39;id&#39;],)) return render_template(&#39;student/grades.html&#39;, grades=grades, student=student) except Exception as e: flash(f&#39;加载成绩列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) @app.route(&#39;/student/classrooms&#39;) @login_required(role=&#39;student&#39;) def student_classrooms(): try: classrooms = execute_query("SELECT * FROM classroom ORDER BY create_time DESC") return render_template(&#39;student/classrooms.html&#39;, classrooms=classrooms) except Exception as e: flash(f&#39;加载教室列表失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) @app.route(&#39;/student/profile&#39;) @login_required(role=&#39;student&#39;) def student_profile(): try: user_id = session[&#39;user_id&#39;] student_details = execute_query(""" SELECT s.*, b.banji_name, y.yuanxi_name, u.username FROM student s JOIN user u ON s.user_id = u.id LEFT JOIN banji b ON s.banji_types = b.id LEFT JOIN yuanxi y ON b.yuanxi_id = y.id WHERE s.user_id = %s """, (user_id,)) if not student_details: flash(&#39;学生信息不存在!&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) student = student_details[0] return render_template(&#39;student/profile.html&#39;, student=student) except Exception as e: flash(f&#39;加载个人信息失败: {str(e)}&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) @app.route(&#39;/student/change_password&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;]) @login_required(role=&#39;student&#39;) def student_change_password(): if request.method == &#39;POST&#39;: old_password = request.form.get(&#39;old_password&#39;) new_password = request.form.get(&#39;new_password&#39;) confirm_password = request.form.get(&#39;confirm_password&#39;) if new_password != confirm_password: flash(&#39;新密码和确认密码不一致!&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_change_password&#39;)) try: user = execute_query("SELECT * FROM user WHERE id = %s", (session[&#39;user_id&#39;],))[0] if not check_password_hash(user[&#39;password&#39;], old_password): flash(&#39;旧密码错误!&#39;, &#39;error&#39;) return redirect(url_for(&#39;student_change_password&#39;)) execute_query( "UPDATE user SET password = %s WHERE id = %s", (generate_password_hash(new_password), session[&#39;user_id&#39;]), fetch=False ) flash(&#39;密码修改成功!&#39;, &#39;success&#39;) return redirect(url_for(&#39;student_dashboard&#39;)) except Exception as e: flash(f&#39;密码修改失败: {str(e)}&#39;, &#39;error&#39;) return render_template(&#39;student/change_password.html&#39;) # GPA计算函数(辅助函数) def calculate_gpa(grades): total_points = 0 total_credits = 0 for grade in grades: score = grade[&#39;grade_score&#39;] credits = grade[&#39;course_xuefen&#39;] # 计算绩点 if score >= 90: points = 4.0 elif score >= 85: points = 3.7 elif score >= 82: points = 3.3 elif score >= 78: points = 3.0 elif score >= 75: points = 2.7 elif score >= 72: points = 2.3 elif score >= 68: points = 2.0 elif score >= 64: points = 1.5 elif score >= 60: points = 1.0 else: points = 0.0 total_points += points * credits total_credits += credits return total_points / total_credits if total_credits > 0 else 0 # ========== 其他功能路由 ========== @app.route(&#39;/init_password&#39;) def init_password(): """初始化用户密码 - 仅在开发环境使用""" try: users = execute_query("SELECT * FROM user") for user in users: execute_query( "UPDATE user SET password = %s WHERE id = %s", (generate_password_hash(&#39;123456&#39;), user[&#39;id&#39;]), fetch=False ) return &#39;密码初始化成功! 所有用户密码已设置为: 123456&#39; except Exception as e: return f&#39;密码初始化失败: {str(e)}&#39; if __name__ == &#39;__main__&#39;: app.run(debug=True, host=&#39;0.0.0.0&#39;, port=5000)。对应的前端代码均已完成。有缺陷。管理和教师面板没有问题,可以正常跳转。学生面板,登录之后,没有反应,没有跳转
10-23
ava实现Web学生选课管理系统 一、系统介绍 1.软件环境 2.系统功能 3.数据库 二、系统展示 1.登录页面 2.学生-主页面 3.学生-查看个人信息 4.学生-选择课程 5.学生-查看已选课程 6.教师-主页面 7.教师-查看个人信息 8.教师-评分 9.教师-查看任课信息 10.管理员-主页面 11.管理员-管理员功能-查看个人信息 12.管理员-管理员功能-添加新的管理员 13.管理员-学生功能-添加学生 14.管理员-学生功能-获取所有学生 15.管理员-课程功能-添加课程 16.管理员-课程功能-查询课程 17.管理员-教师功能-添加教师 18.管理员-教师功能-获取所有教师 三、部分代码 AdminDaoImpl.java CourseDaoImpl.java StudentCourseTeacherDaoImpl.java StudentDaoImpl.java TeacherCourseDaoImpl.javab TeacherDaoImpl.java addAdmin.jsp addCourse.jsp addStudent.jsp addTeacher.jsp 四、其他 1.其他系统实现 JavaWeb系统系列实现 JavaSwing系统系列实现 2.获取源码 3.备注 4.鸡汤 一、系统介绍 1.软件环境 Java:jdk1.8 Mysql:8.0.13 Tomcat:8.5.23 2.系统功能 学生 1.查看个人信息 2.选课 3.查看已选课程 教师 1.查看个人信息 2.评分 3.查看任课课程 管理员 1.管理员功能 (1).查看个人信息 (2).添加新的管理员 2.学生功能 (1).添加学生 (2).获取所有学生 3.课程功能 (1).添加课程 (2).查询课程 4.教师功能 (1).添加教师 (2)获取所有教师 3.数据库 /* Navicat Premium Data Transfer Source Server : MySQL Source Server Type : MySQL Source Server Version : 80013 Source Host : localhost:3306 Source Schema : jsp_servlet_selectcourse Target Server Type : MySQL Target Server Version : 80013 File Encoding : 65001 Date: 23/06/2021 20:46:30 */ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for t_admin -- ---------------------------- DROP TABLE IF EXISTS `t_admin`; CREATE TABLE `t_admin` ( `userid` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `username` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `password` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `age` int(3) NULL DEFAULT NULL, `score` decimal(5, 1) NULL DEFAULT NULL, `introduction` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `enterdate` date NULL DEFAULT NULL, PRIMARY KEY (`userid`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of t_admin -- ---------------------------- INSERT INTO `t_admin` VALUES (&#39;admin&#39;, &#39;管理员&#39;, &#39;admin&#39;, 21, 100.0, &#39; &#39;, &#39;2018-06-12&#39;); INSERT INTO `t_admin` VALUES (&#39;admin1&#39;, &#39;水坚石青&#39;, &#39;admin1&#39;, 25, 99.0, &#39;&#39;, &#39;2021-06-22&#39;); -- ---------------------------- -- Table structure for t_class -- ---------------------------- DROP TABLE IF EXISTS `t_class`; CREATE TABLE `t_class` ( `classno` int(4) NOT NULL AUTO_INCREMENT, `cname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `cteacher` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `classroom` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, PRIMARY KEY (`classno`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1531 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of t_class -- ---------------------------- INSERT INTO `t_class` VALUES (1520, &#39;软工&#39;, &#39;赵丽&#39;, &#39;综阶1&#39;); INSERT INTO `t_class` VALUES (1521, &#39;软工&#39;, &#39;齐兴斌&#39;, &#39;综阶2&#39;); INSERT INTO `t_class` VALUES (1522, &#39;软工&#39;, &#39;张志斌&#39;, &#39;综阶3&#39;); INSERT INTO `t_class` VALUES (1523, &#39;软工&#39;, &#39;郭小英&#39;, &#39;综阶5&#39;); INSERT INTO `t_class` VALUES (1524, &#39;软工&#39;, &#39;郭新峰&#39;, &#39;综阶6&#39;); INSERT INTO `t_class` VALUES (1525, &#39;软工&#39;, &#39;王若慧&#39;, &#39;综阶7&#39;); INSERT INTO `t_class` VALUES (1526, &#39;软工&#39;, &#39;贾春华&#39;, &#39;综阶8&#39;); INSERT INTO `t_class` VALUES (1527, &#39;软工&#39;, &#39;朱云雷&#39;, &#39;综阶9&#39;); INSERT INTO `t_class` VALUES (1528, &#39;软工&#39;, &#39;李雪梅&#39;, &#39;综阶10&#39;); INSERT INTO `t_class` VALUES (1529, &#39;软工&#39;, &#39;张举 &#39;, &#39;综阶11&#39;); INSERT INTO `t_class` VALUES (1530, &#39;软工&#39;, &#39;米晓萍&#39;, &#39;综阶12&#39;); INSERT INTO `t_class` VALUES (1531, &#39;软工&#39;, &#39;张建英&#39;, &#39;综阶13&#39;); -- ---------------------------- -- Table structure for t_course -- ---------------------------- DROP TABLE IF EXISTS `t_course`; CREATE TABLE `t_course` ( `cno` int(4) NOT NULL AUTO_INCREMENT, `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `credit` int(1) NULL DEFAULT NULL, `periodstart` date NULL DEFAULT NULL, `periodend` date NULL DEFAULT NULL, PRIMARY KEY (`cno`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1009 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of t_course -- ---------------------------- INSERT INTO `t_course` VALUES (1001, &#39;数据库&#39;, 4, &#39;2018-02-01&#39;, &#39;2018-08-08&#39;); INSERT INTO `t_course` VALUES (1002, &#39;数据结构&#39;, 4, &#39;2018-02-01&#39;, &#39;2018-08-08&#39;); INSERT INTO `t_course` VALUES (1003, &#39;j2ee&#39;, 4, &#39;2018-02-01&#39;, &#39;2018-08-08&#39;); INSERT INTO `t_course` VALUES (1004, &#39;计算机网络&#39;, 4, &#39;2018-02-01&#39;, &#39;2018-08-08&#39;); INSERT INTO `t_course` VALUES (1005, &#39;计算机组成原理&#39;, 4, &#39;2018-02-01&#39;, &#39;2018-08-08&#39;); INSERT INTO `t_course` VALUES (1007, &#39;编译原理&#39;, 4, &#39;2018-02-01&#39;, &#39;2018-08-08&#39;); INSERT INTO `t_course` VALUES (1008, &#39;C语言&#39;, 4, &#39;2018-02-01&#39;, &#39;2018-02-01&#39;); INSERT INTO `t_course` VALUES (1009, &#39;c++&#39;, 4, &#39;2018-01-02&#39;, &#39;2018-05-28&#39;); INSERT INTO `t_course` VALUES (1010, &#39;1&#39;, 1, &#39;2021-06-22&#39;, &#39;2021-06-22&#39;); -- ---------------------------- -- Table structure for t_sc -- ---------------------------- DROP TABLE IF EXISTS `t_sc`; CREATE TABLE `t_sc` ( `sno` int(10) NOT NULL, `cno` int(4) NOT NULL, `tno` int(4) NOT NULL, `score` decimal(5, 2) NULL DEFAULT NULL, PRIMARY KEY (`sno`, `cno`, `tno`) USING BTREE, INDEX `t_sc_ibfk_2`(`cno`) USING BTREE, INDEX `t_sc_ibfk_3`(`tno`) USING BTREE, CONSTRAINT `t_sc_ibfk_1` FOREIGN KEY (`sno`) REFERENCES `t_student` (`sno`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `t_sc_ibfk_2` FOREIGN KEY (`cno`) REFERENCES `t_course` (`cno`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `t_sc_ibfk_3` FOREIGN KEY (`tno`) REFERENCES `t_teacher` (`tno`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of t_sc -- ---------------------------- INSERT INTO `t_sc` VALUES (2015001, 1002, 1001, 100.00); INSERT INTO `t_sc` VALUES (2015001, 1004, 1001, 99.00); INSERT INTO `t_sc` VALUES (2015001, 1004, 1006, NULL); INSERT INTO `t_sc` VALUES (2015001, 1005, 1002, NULL); INSERT INTO `t_sc` VALUES (2015001, 1007, 1004, NULL); INSERT INTO `t_sc` VALUES (2015001, 1008, 1002, NULL); INSERT INTO `t_sc` VALUES (2015001, 1008, 1004, NULL); INSERT INTO `t_sc` VALUES (2015001, 1008, 1005, NULL); -- ---------------------------- -- Table structure for t_student -- ---------------------------- DROP TABLE IF EXISTS `t_student`; CREATE TABLE `t_student` ( `sno` int(9) NOT NULL AUTO_INCREMENT, `password` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `sname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `phone` bigint(11) NULL DEFAULT NULL, `sex` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `birthday` date NULL DEFAULT NULL, `classno` int(4) NULL DEFAULT NULL, `remark` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, PRIMARY KEY (`sno`) USING BTREE, INDEX `t_student_ibfk_1`(`classno`) USING BTREE, CONSTRAINT `t_student_ibfk_1` FOREIGN KEY (`classno`) REFERENCES `t_class` (`classno`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB AUTO_INCREMENT = 2015570 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of t_student -- ---------------------------- INSERT INTO `t_student` VALUES (2015001, &#39;123456&#39;, &#39;李四&#39;, 15788888888, &#39;女&#39;, &#39;2021-06-22&#39;, 1525, &#39;优秀&#39;); INSERT INTO `t_student` VALUES (2015002, &#39;123456&#39;, &#39;王茹&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;良好&#39;); INSERT INTO `t_student` VALUES (2015003, &#39;123456&#39;, &#39;张三&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;良好&#39;); INSERT INTO `t_student` VALUES (2015004, &#39;123456&#39;, &#39;王五&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;优秀&#39;); INSERT INTO `t_student` VALUES (2015005, &#39;123456&#39;, &#39;李浩&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;合格&#39;); INSERT INTO `t_student` VALUES (2015006, &#39;123456&#39;, &#39;黄县&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;良好&#39;); INSERT INTO `t_student` VALUES (2015007, &#39;123456&#39;, &#39;钱一&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;优秀&#39;); INSERT INTO `t_student` VALUES (2015009, &#39;123456&#39;, &#39;赵括&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;优秀&#39;); INSERT INTO `t_student` VALUES (2015010, &#39;123456&#39;, &#39;赵括&#39;, 15788888888, &#39;女&#39;, &#39;2018-05-28&#39;, 1520, &#39;优秀&#39;); -- ---------------------------- -- Table structure for t_tc -- ---------------------------- DROP TABLE IF EXISTS `t_tc`; CREATE TABLE `t_tc` ( `cno` int(4) NOT NULL, `tno` int(4) NOT NULL, PRIMARY KEY (`cno`, `tno`) USING BTREE, INDEX `t_tc_ibfk_2`(`tno`) USING BTREE, CONSTRAINT `t_tc_ibfk_1` FOREIGN KEY (`cno`) REFERENCES `t_course` (`cno`) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT `t_tc_ibfk_2` FOREIGN KEY (`tno`) REFERENCES `t_teacher` (`tno`) ON DELETE RESTRICT ON UPDATE RESTRICT ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of t_tc -- ---------------------------- INSERT INTO `t_tc` VALUES (1001, 1001); INSERT INTO `t_tc` VALUES (1002, 1001); INSERT INTO `t_tc` VALUES (1004, 1001); INSERT INTO `t_tc` VALUES (1009, 1001); INSERT INTO `t_tc` VALUES (1005, 1002); INSERT INTO `t_tc` VALUES (1008, 1002); INSERT INTO `t_tc` VALUES (1002, 1003); INSERT INTO `t_tc` VALUES (1004, 1003); INSERT INTO `t_tc` VALUES (1007, 1004); INSERT INTO `t_tc` VALUES (1008, 1004); INSERT INTO `t_tc` VALUES (1008, 1005); INSERT INTO `t_tc` VALUES (1004, 1006); -- ---------------------------- -- Table structure for t_teacher -- ---------------------------- DROP TABLE IF EXISTS `t_teacher`; CREATE TABLE `t_teacher` ( `tno` int(4) NOT NULL AUTO_INCREMENT, `tname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `password` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `phone` bigint(11) NULL DEFAULT NULL, `hiredate` date NULL DEFAULT NULL, `remark` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, PRIMARY KEY (`tno`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1006 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of t_teacher -- ---------------------------- INSERT INTO `t_teacher` VALUES (1001, &#39;张志斌&#39;, &#39;123456&#39;, 15788888888, &#39;2017-07-20&#39;, &#39;张老师是一个超级幽默的老师,教学认真,态度友好,有自己独有的教学方法,深得学生喜爱&#39;); INSERT INTO `t_teacher` VALUES (1002, &#39;白茹意&#39;, &#39;123456&#39;, 15766666666, &#39;2018-03-06&#39;, &#39;白老师工作认真负责,不推卸责任&#39;); INSERT INTO `t_teacher` VALUES (1003, &#39;郭新峰&#39;, &#39;123456&#39;, 15733333333, &#39;2018-05-14&#39;, &#39;<span style=\"font-family:Arial Black;\"><span style=\"color:#E53333;\"><span style=\"color:#E53333;\">郭老师很认真负责</span></span></span>&#39;); INSERT INTO `t_teacher` VALUES (1004, &#39;赵丽&#39;, &#39;123456&#39;, 15722222222, &#39;2018-04-03&#39;, NULL); INSERT INTO `t_teacher` VALUES (1005, &#39;齐兴斌&#39;, &#39;123456&#39;, 15711111111, &#39;2004-05-28&#39;, NULL); INSERT INTO `t_teacher` VALUES (1006, &#39;尹少平&#39;, &#39;123456&#39;, 15777777777, &#39;2014-06-11&#39;, NULL); SET FOREIGN_KEY_CHECKS = 1; AI写代码 sql 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 二、系统展示 1.登录页面 2.学生-主页面 3.学生-查看个人信息 4.学生-选择课程 5.学生-查看已选课程 6.教师-主页面 7.教师-查看个人信息 8.教师-评分 9.教师-查看任课信息 10.管理员-主页面 11.管理员-管理员功能-查看个人信息 12.管理员-管理员功能-添加新的管理员 13.管理员-学生功能-添加学生 14.管理员-学生功能-获取所有学生 15.管理员-课程功能-添加课程 16.管理员-课程功能-查询课程 17.管理员-教师功能-添加教师 18.管理员-教师功能-获取所有教师 三、部分代码 AdminDaoImpl.java package com.bluehonour.sscs.dao.impl; import java.sql.Connection; import java.util.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.bluehonour.sscs.dao.AdminDao; import com.bluehonour.sscs.entity.Admin; import com.bluehonour.sscs.util.DBUtils; public class AdminDaoImpl implements AdminDao{ @Override public Admin find(String userId, String password) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; Admin admin = null; try { //建立连接 connection = DBUtils.getConnection(); //向数据库发送sql命令并得到结果 String sql = "select * from t_admin where userid = ? and password = ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, userId); preparedStatement.setString(2, password); rs = preparedStatement.executeQuery(); //处理返回结果 if(rs.next()) { //取出结果集当前行各个字段的值 String userName = rs.getString("username"); int age = rs.getInt("age"); double score = rs.getDouble("score"); Date enterDate = rs.getDate("enterdate"); String introduction = rs.getString("introduction"); //封装成对象 admin = new Admin(userId, userName, password, age, score, enterDate, introduction); } } catch (SQLException e) { e.printStackTrace(); } finally { //关闭数据库资源 DBUtils.closeAll(rs, preparedStatement, connection); } return admin; } @Override public int save(Admin admin) { String sql = "insert into t_admin values(?,?,?,?,?,?,?)"; Object[] params = {admin.getUserId(),admin.getUserName(),admin.getPassword(),admin.getAge(), admin.getScore(),admin.getIntroduction(),admin.getEnterDate()}; return DBUtils.executeUpdate(sql, params); } } AI写代码 java 运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 CourseDaoImpl.java package com.bluehonour.sscs.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.bluehonour.sscs.dao.CourseDao; import com.bluehonour.sscs.entity.Course; import com.bluehonour.sscs.util.DBUtils; public class CourseDaoImpl implements CourseDao{ @Override public int save(Course course) { String sql = "insert into t_course (name,credit,periodstart,periodend) values(?,?,?,?) "; Object[] params = {course.getName(), course.getCredit(), course.getPeriodstart(), course.getPeriodend()}; return DBUtils.executeUpdate(sql, params); } @Override public List<Course> findAll() { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; List<Course> list = new ArrayList<Course>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select * from t_course order by cno"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行各个字段的值 int cno = rs.getInt("cno"); String name = rs.getString("name"); int credit = rs.getInt("credit"); Date periodstart = rs.getDate("periodstart"); Date periodend = rs.getDate("periodend"); // 封装成对象 Course course = new Course(cno,name, credit, periodstart, periodend); list.add(course); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return list; } } AI写代码 java 运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 StudentCourseTeacherDaoImpl.java package com.bluehonour.sscs.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.bluehonour.sscs.dao.StudentCourseTeacherDao; import com.bluehonour.sscs.entity.Course; import com.bluehonour.sscs.entity.StudentCourse; import com.bluehonour.sscs.entity.Teacher; import com.bluehonour.sscs.util.DBUtils; public class StudentCourseTeacherDaoImpl implements StudentCourseTeacherDao { @Override public int save(int sno, int cno, int tno) { String sql = "insert into t_sc(sno,cno,tno) values(?,?,?)"; Object[] params = {sno,cno,tno}; return DBUtils.executeUpdate(sql, params); } @Override public List<Course> findSelectedCourse(int sno) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; List<Course> list = new ArrayList<Course>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select * from t_course c" + " join t_sc sc" + " on (c.cno = sc.cno)" + " join t_teacher t" + " on (sc.tno = t.tno)" + " where sno = " + sno; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行课程各个字段的值 int cno = rs.getInt("cno"); String name = rs.getString("name"); int credit = rs.getInt("credit"); Date periodstart = rs.getDate("periodstart"); Date periodend = rs.getDate("periodend"); // 封装成课程对象 Course course = new Course(cno,name, credit, periodstart, periodend); //取出结果集中教师各个字段的值 int tno = rs.getInt("tno"); String tname = rs.getString("tname"); String password = rs.getString("password"); long phone = rs.getLong("phone"); Date hiredate = rs.getDate("hiredate"); String remark = rs.getString("remark"); //封装成教师对象 Teacher teacher = new Teacher(tno,tname, password, phone, hiredate, remark); //将教师加入课程 course.setTeacher(teacher); list.add(course); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return list; } @Override public List<Course> findSelectableCourse(int sno) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; List<Course> list = new ArrayList<Course>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "SELECT c.*, t.* FROM t_tc a " + "LEFT JOIN t_course c " + "ON a.cno = c.cno " + "LEFT JOIN t_teacher t " + "ON a.tno = t.tno " + "WHERE (a.cno, a.tno) NOT IN " + "( SELECT cno,tno " + "FROM t_sc " + "WHERE sno = " + sno +") "; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行课程各个字段的值 int cno = rs.getInt("cno"); String name = rs.getString("name"); int credit = rs.getInt("credit"); Date periodstart = rs.getDate("periodstart"); Date periodend = rs.getDate("periodend"); // 封装成课程对象 Course course = new Course(cno,name, credit, periodstart, periodend); //取出结果集中教师各个字段的值 int tno = rs.getInt("tno"); String tname = rs.getString("tname"); String password = rs.getString("password"); long phone = rs.getLong("phone"); Date hiredate = rs.getDate("hiredate"); String remark = rs.getString("remark"); //封装成教师对象 Teacher teacher = new Teacher(tno,tname, password, phone, hiredate, remark); //将教师加入课程 course.setTeacher(teacher); list.add(course); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return list; } @Override public int removeStudentDistributedCourse(int sno, int cno, int tno) { String sql = "delete from t_sc where sno = ? and cno = ? and tno = ?"; Object[] params = {sno,cno,tno}; return DBUtils.executeUpdate(sql, params); } @Override public List<StudentCourse> getSelectedStudentAndCourse(int tno) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; List<StudentCourse> list = new ArrayList<StudentCourse>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "SELECT" + " s.sno," + " s.sname," + " s.classno," + " clazz.cname," + " c.cno," + " c. NAME," + " c.credit," + " sc.score" + " FROM" + " t_student s" + " LEFT JOIN t_class clazz ON clazz.classno = s.classno" + " LEFT JOIN t_sc sc ON sc.sno = s.sno" + " LEFT JOIN t_course c ON c.cno = sc.cno" + " WHERE" + " sc.tno = " + tno + " ORDER BY" + " c.cno," + " s.sno"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { int cno = rs.getInt("cno"); String name = rs.getString("name"); int credit = rs.getInt("credit"); int sno = rs.getInt("sno"); int classno = rs.getInt("classno"); String sname = rs.getString("sname"); String cname = rs.getString("cname"); double score = rs.getDouble("score"); //封装成教师对象 StudentCourse sc = new StudentCourse(sno, sname, classno, cname, cno, name, credit, score); list.add(sc); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return list; } @Override public int courseRemark(int sno, int cno, int tno, double score) { String sql = "update t_sc set score = ? where sno = ? and cno = ? and tno = ?"; Object[] params = {score,sno,cno,tno}; return DBUtils.executeUpdate(sql, params); } } AI写代码 java 运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 StudentDaoImpl.java package com.bluehonour.sscs.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.bluehonour.sscs.dao.StudentDao; import com.bluehonour.sscs.entity.ClassInfo; import com.bluehonour.sscs.entity.CriteriaStudent; import com.bluehonour.sscs.entity.Student; import com.bluehonour.sscs.util.DBUtils; public class StudentDaoImpl implements StudentDao { @Override public int save(Student stu) { String sql = "insert into t_student(password,sname,phone,sex,birthday,classno,remark) values(?,?,?,?,?,?,?)"; Object[] params = { stu.getPassword(), stu.getSname(), stu.getPhone(), stu.getSex(), stu.getBirthday(), stu.getClassno(), stu.getRemark() }; return DBUtils.executeUpdate(sql, params); } @Override public List<Student> findAll() { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; Student student = null; List<Student> stuList = new ArrayList<Student>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select * from t_student"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行各个字段的值 int sno = rs.getInt("sno"); String password = rs.getString("password"); String sname = rs.getString("sname"); long phone = rs.getLong("phone"); String sex = rs.getString("sex"); Date birthday = rs.getDate("birthday"); int classno = rs.getInt("classno"); String remark = rs.getString("remark"); // 封装成对象 student = new Student(sno,password, sname, phone, sex, birthday, classno, remark); stuList.add(student); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return stuList; } @Override public int del(int sno) { String sql = "delete from t_student where sno = ?"; Object[] params = {sno }; return DBUtils.executeUpdate(sql, params); } @Override public Student findById(int sno) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; Student student = null; try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select * from t_student where sno = " + sno; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 if (rs.next()) { // 取出结果集当前行各个字段的值 String password = rs.getString("password"); String sname = rs.getString("sname"); long phone = rs.getLong("phone"); String sex = rs.getString("sex"); Date birthday = rs.getDate("birthday"); int classno = rs.getInt("classno"); String remark = rs.getString("remark"); // 封装成对象 student = new Student(sno,password, sname, phone, sex, birthday, classno, remark); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return student; } @Override public int update(Student stu) { String sql = "update t_student set sname=?,password=?,phone=?,birthday=?,sex=?,classno=?,remark=? where sno=?"; Object[] params = { stu.getSname(),stu.getPassword(),stu.getPhone(),stu.getBirthday(),stu.getSex(),stu.getClassno(), stu.getRemark(),stu.getSno() }; return DBUtils.executeUpdate(sql, params); } @Override public Student find(String sno, String password) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; Student student = null; try { //建立连接 connection = DBUtils.getConnection(); //向数据库发送sql命令并得到结果 String sql = "select * from t_student where sno = ? and password = ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, sno); preparedStatement.setString(2, password); rs = preparedStatement.executeQuery(); //处理返回结果 if(rs.next()) { //取出结果集当前行各个字段的值 String sname = rs.getString("sname"); long phone = rs.getLong("phone"); String sex = rs.getString("sex"); Date birthday = rs.getDate("birthday"); int classno = rs.getInt("classno"); String remark = rs.getString("remark"); //封装成对象 student = new Student(Integer.parseInt(sno), password, sname, phone, sex, birthday, classno, remark); } } catch (SQLException e) { e.printStackTrace(); } finally { //关闭数据库资源 DBUtils.closeAll(rs, preparedStatement, connection); } return student; } @Override public List<ClassInfo> getClassInfo() { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; ClassInfo clazz = null; List<ClassInfo> list = new ArrayList<ClassInfo>(); try { //建立连接 connection = DBUtils.getConnection(); //向数据库发送sql命令并得到结果 String sql = "select * from t_class"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); //处理返回结果 while(rs.next()) { //取出结果集当前行各个字段的值 int classno = rs.getInt("classno"); String cname = rs.getString("cname"); String cteacher = rs.getString("cteacher"); String classroom = rs.getString("classroom"); //封装成对象 clazz = new ClassInfo(classno, cname, cteacher, classroom); list.add(clazz); } } catch (SQLException e) { e.printStackTrace(); } finally { //关闭数据库资源 DBUtils.closeAll(rs, preparedStatement, connection); } return list; } @Override public List<Student> getForListWithCriteriaStudent(CriteriaStudent student) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; List<Student> stuList = new ArrayList<Student>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 StringBuffer sql = new StringBuffer(); sql.append("select * from t_student"); if(!student.getSno().equals("")) { sql.append(" and sno like &#39;%"+ student.getSno() +"%&#39;"); } if(!student.getSname().equals("")) { sql.append(" and sname like &#39;%"+ student.getSname() +"%&#39;"); } if(!student.getSex().equals("")) { sql.append(" and sex =&#39;"+ student.getSex() +"&#39;"); } if(!student.getClassno().equals("")) { sql.append(" and classno like &#39;%"+ student.getClassno() +"%&#39;"); } if(!student.getRemark().equals("")) { sql.append(" and remark=&#39;"+ student.getRemark() +"&#39;"); } String SQL = sql.toString(); SQL = SQL.replaceFirst("and", "where"); System.out.println(SQL); preparedStatement = connection.prepareStatement(SQL); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行各个字段的值 int sno = rs.getInt("sno"); String password = rs.getString("password"); String sname = rs.getString("sname"); long phone = rs.getLong("phone"); String sex = rs.getString("sex"); Date birthday = rs.getDate("birthday"); int classno = rs.getInt("classno"); String remark = rs.getString("remark"); // 封装成对象 Student stu = new Student(sno,password, sname, phone, sex, birthday, classno, remark); stuList.add(stu); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return stuList; } } AI写代码 java 运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 TeacherCourseDaoImpl.javab package com.bluehonour.sscs.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.bluehonour.sscs.dao.TeacherCourseDao; import com.bluehonour.sscs.entity.Course; import com.bluehonour.sscs.entity.Teacher; import com.bluehonour.sscs.util.DBUtils; public class TeacherCourseDaoImpl implements TeacherCourseDao { @Override public int save(int cno, int tno) { String sql = "insert into t_tc values(?,?)"; Object[] params = {cno,tno}; return DBUtils.executeUpdate(sql, params); } @Override public int delete(int cno, int tno) { String sql = "delete from t_tc where cno = ? and tno = ?"; Object[] params = {cno,tno}; return DBUtils.executeUpdate(sql, params); } @Override public List<Course> findAll() { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; List<Course> list = new ArrayList<Course>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select * from t_course c" + " join t_tc tc" + " on (c.cno = tc.cno)" + " join t_teacher t" + " on (tc.tno = t.tno)" + " order by c.cno"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行课程各个字段的值 int cno = rs.getInt("cno"); String name = rs.getString("name"); int credit = rs.getInt("credit"); Date periodstart = rs.getDate("periodstart"); Date periodend = rs.getDate("periodend"); // 封装成课程对象 Course course = new Course(cno,name, credit, periodstart, periodend); //取出结果集中教师各个字段的值 int tno = rs.getInt("tno"); String tname = rs.getString("tname"); String password = rs.getString("password"); long phone = rs.getLong("phone"); Date hiredate = rs.getDate("hiredate"); String remark = rs.getString("remark"); //封装成教师对象 Teacher teacher = new Teacher(tno,tname, password, phone, hiredate, remark); //将教师加入课程 course.setTeacher(teacher); list.add(course); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return list; } } AI写代码 java 运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 TeacherDaoImpl.java package com.bluehonour.sscs.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.bluehonour.sscs.dao.TeacherDao; import com.bluehonour.sscs.entity.Course; import com.bluehonour.sscs.entity.Student; import com.bluehonour.sscs.entity.Teacher; import com.bluehonour.sscs.util.DBUtils; public class TeacherDaoImpl implements TeacherDao { @Override public int save(Teacher teacher) { String sql = "insert into t_teacher(tname,password,phone,hiredate,remark) values(?,?,?,?,?) "; Object[] params = {teacher.getTname(),teacher.getPassword(),teacher.getPhone(),teacher.getHiredate(),teacher.getRemark()}; return DBUtils.executeUpdate(sql, params); } @Override public List<Teacher> findAll() { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; List<Teacher> list = new ArrayList<Teacher>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select * from t_teacher order by tno"; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行各个字段的值 int tno = rs.getInt("tno"); String tname = rs.getString("tname"); String password = rs.getString("password"); long phone = rs.getLong("phone"); Date hiredate = rs.getDate("hiredate"); String remark = rs.getString("remark"); // 封装成对象 Teacher teacher = new Teacher(tno,tname, password, phone, hiredate, remark); list.add(teacher); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return list; } @Override public int delete(int tno) { String sql = "delete from t_teacher where tno = ?"; Object[] params = {tno }; return DBUtils.executeUpdate(sql, params); } @Override public Teacher findById(int tno) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; Teacher teacher = null; try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select * from t_teacher where tno = " + tno; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 if (rs.next()) { // 取出结果集当前行各个字段的值 String tname = rs.getString("tname"); String password = rs.getString("password"); long phone = rs.getLong("phone"); Date hiredate = rs.getDate("hiredate"); String remark = rs.getString("remark"); // 封装成对象 teacher = new Teacher(tno, tname, password, phone, hiredate, remark); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return teacher; } @Override public int update(Teacher teacher) { String sql = "update t_teacher set tname=?,password=?,phone=?,hiredate=?,remark=? where tno=?"; Object[] params = {teacher.getTname(),teacher.getPassword(),teacher.getPhone(),teacher.getHiredate(),teacher.getRemark(),teacher.getTno()}; return DBUtils.executeUpdate(sql, params); } @Override public List<Course> getAssumeCourse(int tno) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet rs = null; Course course = null; List<Course> list = new ArrayList<>(); try { // 建立连接 connection = DBUtils.getConnection(); // 向数据库发送sql命令并得到结果 String sql = "select c.* from t_tc tc " + "LEFT JOIN t_teacher t on t.tno = tc.tno " + "LEFT JOIN t_course c on c.cno = tc.cno " + "where tc.tno = " + tno ; preparedStatement = connection.prepareStatement(sql); rs = preparedStatement.executeQuery(); // 处理返回结果 while (rs.next()) { // 取出结果集当前行各个字段的值 int cno = rs.getInt("cno"); String name = rs.getString("name"); int credit = rs.getInt("credit"); Date periodstart = rs.getDate("periodstart"); Date periodend = rs.getDate("periodend"); // 封装成对象 course = new Course(cno,name, credit, periodstart, periodend); list.add(course); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeAll(rs, preparedStatement, connection); } return list; } } AI写代码 java 运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 addAdmin.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head lang="en"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>增加管理员</title> <link rel="stylesheet" type="text/css" href="<c:url value=&#39;/css/add.css&#39;/>"> <script type="text/javascript" src="${pageContext.request.contextPath }/My97DatePicker/WdatePicker.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath }/kindeditor/kindeditor-all.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath }/kindeditor/lang/zh_CN.js"></script> <script> KindEditor.ready(function(K) { filterMode: false,//是否开启过滤模式 window.editor = K.create(&#39;#introduction-id&#39;); }); </script> </head> <body> <div class="nav"> <%-- ${error } <div><img src="${pageContext.request.contextPath }/images/register_admin.jpg"></div> --%> <% if(request.getAttribute("error") != null){ %> <div><img src="${pageContext.request.contextPath }/images/add_admin_error.jpg"></div> <% } else{ %> <div><img src="${pageContext.request.contextPath }/images/register_admin.jpg"></div> <% } %> <div class="nav1"> <form action="${pageContext.request.contextPath }/addAdmin.do" method="post"> <p> <label for="userId">管理员账号:</label> <input type="text" name="userId" id="userId""><span>请输入4-10位用户名</span> </p> <p> <label for="userName">真实姓名:</label> <input type="text" name="userName" id="userName" value=""><span>请输入您的真实姓名</span> </p> <p> <label for="passWord">密码:</label> <input type="password" name="passWord" id="passWord" value="" size="20px"><span>密码为6-16位</span> </p> <p> <label for="rePassWord">确认密码:</label> <input type="password" name="rePassWord" id="rePassWord" value="" size="20px"><span>请再次输入密码</span> </p> <p> <label for="age">年龄:</label> <input type="text" name="age" id="age" value=""><span>请输入年龄</span> </p> <p> <label for="score">成绩:</label> <input type="text" name="score" id="score" value=""><span>请输入成绩</span> </p> <p> <label for="enterDate">入职时间:</label> <input type="text" name="enterDate" id="enterDate" value="" onfocus="WdatePicker({highLineWeekDay:true,isShowToday:true,isShowWeek:true})"><span>请输入入职时间</span> </p> <p> <label for="introduction">简介:</label> <textarea class="no" name="introduction" id="introduction-id" style=" width: 700px; height: 200px; visibility: hidden; display: block;"> </textarea> </p> <button class="sub"> <img src="${pageContext.request.contextPath }/images/button.gif"> </button> </form> </div> </div> <script> window.onload = function(e) { var form = document.querySelector(&#39;form&#39;); var userId = document.querySelector(&#39;#userId&#39;); var userName = document.querySelector(&#39;#userName&#39;); var passWord = document.querySelector(&#39;#passWord&#39;); var rePassWord = document.querySelector(&#39;#rePassWord&#39;); var age = document.querySelector(&#39;#age&#39;); var score = document.querySelector(&#39;#score&#39;); var enterDate = document.querySelector(&#39;#enterDate&#39;); var span = document.querySelectorAll(&#39;span&#39;); //onsubmit事件 form.onsubmit = function(e) { var userId = checkUserId(); if (!userId) { return false; } var username = checkUserName(); if (!username) { return false; } var password = checkPassWord(); if (!password) { return false; } var rePassWord = checkRePassWord(); if (!rePassWord) { return false; } var age = checkAge(); if (!age) { return false; } var score = checkScore(); if (!score) { return false; } var enterDate = checkEnterDate(); if (!enterDate) { return false; } return true; }; //onblur失去焦点事件 userId.onblur = function(e) { checkUserId(); }; userName.onblur = function(e) { checkUserName(); }; passWord.onblur = function(e) { checkPassWord(); }; rePassWord.onblur = function(e) { checkRePassWord(); }; age.onblur = function(e) { checkAge(); }; score.onblur = function(e) { checkScore(); }; enterDate.onblur = function(e) { checkEnterDate(); }; //---------------------------------函数封装------------------------------------------------------------- //管理员账户(3-10位) function checkUserId(e) { if (userId.value.length == 0) { span[0].innerText = &#39;账户不能为空&#39;; span[0].className = &#39;danger&#39;; return false; } var pattern = /^[A-Za-z0-9]{3,10}$/; if (!pattern.test(userId.value)) { span[0].innerText = &#39;账户格式错误,请重新输入&#39;; span[0].className = &#39;danger&#39;; return false; } span[0].innerText = &#39;管理员账户输入正确&#39;; span[0].className = &#39;success&#39;; return true; } //真实姓名(2-4位汉字) function checkUserName(e) { if (userName.value.length == 0) { span[1].innerText = &#39;真实姓名不能为空&#39;; span[1].className = &#39;danger&#39;; return false; } var pattern = /^[\u4e00-\u9fa5]{2,4}$/; if (!pattern.test(userName.value)) { span[1].innerText = &#39;真实姓名格式错误,请重新输入&#39;; span[1].className = &#39;danger&#39;; return false; } span[1].innerText = &#39;真实姓名输入正确&#39;; span[1].className = &#39;success&#39;; return true; } //登录密码(6-16位) function checkPassWord(e) { if (passWord.value.length == 0) { span[2].innerText = &#39;密码不能为空&#39;; span[2].className = &#39;danger&#39;; return false; } var pattern = /^[A-Za-z0-9]{6,16}$/; if (!pattern.test(passWord.value)) { span[2].innerText = &#39;密码不符合格式,请重新输入&#39;; span[2].className = &#39;danger&#39;; return false; } span[2].innerText = &#39;密码输入正确&#39;; span[2].className = &#39;success&#39;; return true; } //重复登录密码 function checkRePassWord(e) { if (rePassWord.value.length == 0) { span[3].innerText = &#39;重复密码不能为空&#39;; span[3].className = &#39;danger&#39;; return false; } if (rePassWord.value != passWord.value) { span[3].innerText = &#39;两次输入的密码不一致,请重新输入&#39;; span[3].className = &#39;danger&#39;; return false; } span[3].innerText = &#39;两次密码一致&#39;; span[3].className = &#39;success&#39;; return true; } //年龄(1-3位) function checkAge(e) { if (age.value.length == 0) { span[4].innerText = &#39;年龄不能为空&#39;; span[4].className = &#39;danger&#39;; return false; } var pattern = /^[1-9]{1,3}$/; if (!pattern.test(age.value)) { span[4].innerText = &#39;年龄格式错误,请重新输入&#39;; span[4].className = &#39;danger&#39;; return false; } span[4].innerText = &#39;年龄输入正确&#39;; span[4].className = &#39;success&#39;; return true; } //成绩 function checkScore(e) { if (score.value.length == 0) { span[5].innerText = &#39;成绩不能为空&#39;; span[5].className = &#39;danger&#39;; return false; } /* var pattern = /^[0-9]+\.?[0-9]*$/; */ var pattern = /^[0-9]+\.?[0-9]*$/; if (!pattern.test(score.value)) { span[5].innerText = &#39;成绩格式错误,请重新输入&#39;; span[5].className = &#39;danger&#39;; return false; } span[5].innerText = &#39;成绩输入正确&#39;; span[5].className = &#39;success&#39;; return true; } //入职时间(格式xxxx-xx-xx) function checkEnterDate(e) { if (enterDate.value.length == 0) { span[6].innerText = &#39;入职时间不能为空&#39;; span[6].className = &#39;danger&#39;; return false; } var pattern = /^[0-9]{4}\-?[0-9]{1,2}\-?[0-9]{1,2}$/; if (!pattern.test(enterDate.value)) { span[6].innerText = &#39;时间格式:xxxx-xx-xx&#39;; span[6].className = &#39;danger&#39;; return false; } span[6].innerText = &#39;时间格式正确&#39;; span[6].className = &#39;success&#39;; return true; } } </script> </body> </html> AI写代码 html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 addCourse.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head lang="en"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加学生</title> <link rel="stylesheet" type="text/css" href="<c:url value=&#39;/css/add.css&#39;/>"> <script type="text/javascript" src="${pageContext.request.contextPath }/My97DatePicker/WdatePicker.js"></script> </head> <body> <div class="nav"> <% if(request.getAttribute("error") != null){ %> <div><img src="${pageContext.request.contextPath }/images/add_course_error.jpg"></div> <% } else{ %> <div><img src="${pageContext.request.contextPath }/images/register_course.jpg"></div> <% } %> <div class="nav1"> <form action="${pageContext.request.contextPath }/addCourse.do" method="post"> <p> <label for="name">课程名称:</label> <input type="text" id="name" name="name" value=""> </p> <p> <label for="name">学分:</label> <input type="text" id="credit" name="credit" value=""> </p> <p> <label for="periodStart">开课日期:</label> <input type="text" id="periodStart" name="periodStart" value="" onfocus="WdatePicker({highLineWeekDay:true,isShowToday:true,isShowWeek:true})"> </p> <p> <label for="periodEnd">结课日期:</label> <input type="text" id="periodEnd" name="periodEnd" value="" onfocus="WdatePicker({highLineWeekDay:true,isShowToday:true,isShowWeek:true})"> </p> <div align="center"> <input type="submit" value="保存" /> </div> <div align="center"> ${error } </div> </form> </div> </div> </body> </html> AI写代码 html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 addStudent.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head lang="en"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加学生</title> <link rel="stylesheet" type="text/css" href="<c:url value=&#39;/css/add.css&#39;/>"> <script language="javascript" type="text/javascript" src="${pageContext.request.contextPath }/scripts/student.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath }/My97DatePicker/WdatePicker.js"></script> </head> <body> <div class="nav"> <% if(request.getAttribute("error") != null){ %> <div><img src="${pageContext.request.contextPath }/images/add_admin_error.jpg"></div> <% } else{ %> <div><img src="${pageContext.request.contextPath }/images/register_student.jpg"></div> <% } %> <div class="nav1"> <form action="${pageContext.request.contextPath }/addStudent.do" method="post"> <p> <label for="name">学生姓名:</label> <input type="text" id="name" name="name" value=""><span>请输入学生姓名</span> </p> <p> <label for="password">密码:</label> <input type="text" id="password" name="password" value=""><span>密码为6-16位</span> </p> <p> <label for="classno">班级:</label> <select name="classno" id="classno"> <option>--请选择班级--</option> <c:forEach items="${classList }" var="clazz"> <option>--${clazz.classno}班--</option> </c:forEach> </select> <span style="margin-left: 100px">请输入班级</span> </p> <p> <label>性别:</label> <input type="radio" name="sex" value="男" checked="checked" >男 <input type="radio" name="sex" value="女">女 </p> <p> <label for="tel">关联手机号:</label> <input type="text" id="tel" name="tel" value=""><span>请输入手机号</span> </p> <p> <label for="birthday">出生年月日:</label> <input type="text" id="birthday" name="birthday" value="" onfocus="WdatePicker({highLineWeekDay:true,isShowToday:true,isShowWeek:true})"><span>请输入出生年月日</span> </p> <p> <label for="remark">评论:</label> <select name="remark" id="remark"> <option>--请选择--</option> <option>优秀</option> <option>良好</option> <option>合格</option> <option>差劲</option> </select> <span style="margin-left: 100px">请对该学生进行评论</span> </p> <button class="sub"> <img src="${pageContext.request.contextPath }/images/submit.jpg"> </button> <div align="center"> ${error } </div> </form> </div> </div> </body> </html> AI写代码 html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 addTeacher.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head lang="en"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加教师</title> <link rel="stylesheet" type="text/css" href="<c:url value=&#39;/css/add.css&#39;/>"> <script language="javascript" type="text/javascript" src="${pageContext.request.contextPath }/scripts/teacher.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath }/My97DatePicker/WdatePicker.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath }/kindeditor/kindeditor-all.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath }/kindeditor/lang/zh_CN.js"></script> <script> KindEditor.ready(function(K) { filterMode: false,//是否开启过滤模式 window.editor = K.create(&#39;#remark-id&#39;); }); </script> </head> <body> <div class="nav"> <% if (request.getAttribute("error") != null) { %> <div><img src="${pageContext.request.contextPath }/images/add_teacher_error.jpg"></div> <% } else { %> <div><img src="${pageContext.request.contextPath }/images/register_teacher.jpg"></div> <% } %> <div class="nav1"> <form action="${pageContext.request.contextPath }/addTeacher.do" method="post"> <p> <label for="name">教师姓名:</label> <input type="text" id="name" name="name" value=""><span>请输入教师姓名</span> </p> <p> <label for="password">教师密码:</label> <input type="text" id="password" name="password" value=""><span>密码为6-16位</span> </p> <p> <label for="tel">联系方式:</label> <input type="text" id="tel" name="tel" value=""><span>请输入手机号</span> </p> <p> <label for="hiredate">入职时间:</label> <input type="text" id="hiredate" name="hiredate" value="" onfocus="WdatePicker({highLineWeekDay:true,isShowToday:true,isShowWeek:true})"><span>请输入入职时间</span> </p> <p> <label for="remark">评论:</label> <textarea class="no" name="remark" id="remark-id" style="width: 700px; height: 200px; visibility: hidden; display: block;"> </textarea> </p> <button class="sub"> <img src="${pageContext.request.contextPath }/images/submit.jpg"> </button> <div align="center">${error }</div> </form> </div> </div> </body> </html> AI写代码 html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 四、其他 ———————————————— 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 原文链接:https://blog.youkuaiyun.com/helongqiang/article/details/118162212进行一个总结
07-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值