使用JSP/SERVLET實現(xiàn)在校學(xué)生管理系統(tǒng)
?作者主頁:
?簡介:Java領(lǐng)域優(yōu)質(zhì)創(chuàng)作者、CSDN博客專家? Java項目、簡歷模板、學(xué)習(xí)資料、面試題庫、技術(shù)互助
文末獲取源碼
項目編號: BS-GX-012
本系統(tǒng)基于JSP/SERVLET技術(shù)開發(fā)實現(xiàn),前端采用easyui進行頁面設(shè)計,用戶交互性好,采用三層架構(gòu),MVC設(shè)計模式,數(shù)據(jù)庫采用MYSQL數(shù)據(jù)庫,開發(fā)工具為IDEA或ECLIPSE。
系統(tǒng)分為管理員、老師端、學(xué)生端三個角色!
管理員:進入系統(tǒng)可以進行 學(xué)生管理,教師管理,基礎(chǔ)信息管理(年級管理,班級管理,課程管理),系統(tǒng)管理,成績統(tǒng)計分析管理等。管理員用戶在user表中type類型為1 的用戶。
學(xué)生用戶:進入系統(tǒng)可以? 查詢考試成績,查看班級通訊錄,修改個人信息等。學(xué)生用戶在user表中type類型為2 的用戶。
教師用戶:進入系統(tǒng)可以? 管理學(xué)生成績,查看教師通訊錄,修改個人信息等。
教師用戶在user表中type類型為2 的用戶。
?一,管理員角色進入
登錄功能:? admin?? 111111

管理員功能演示:

班級列表

成績統(tǒng)計

老師信息管理

學(xué)生信息管理

課程管理

年級管理

班級管理

系統(tǒng)管理

二,老師登陸后臺
登陸頁面:? 2012?? /? 111111


學(xué)生成績管理

?老師通訊錄查看

?個人信息管理

三,學(xué)生登陸系統(tǒng)
登陸頁面:201301006?? /? 111111

成績查詢

?班級通訊錄

個人信息管理

本系統(tǒng)功能完整,運行無誤,結(jié)構(gòu)清晰,適合做畢業(yè)設(shè)計使用。
package com.lizhou.service;import java.sql.Connection;import java.util.HashMap;import java.util.LinkedList;import java.util.List;import java.util.Map;import com.lizhou.bean.Clazz;import com.lizhou.bean.Grade;import com.lizhou.bean.Page;import com.lizhou.bean.Student;import com.lizhou.dao.impl.BaseDaoImpl;import com.lizhou.dao.impl.ClazzDaoImpl;import com.lizhou.dao.inter.BaseDaoInter;import com.lizhou.dao.inter.ClazzDaoInter;import com.lizhou.tools.MysqlTool;import com.lizhou.tools.StringTool;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import net.sf.json.JsonConfig;/**
* 年級服務(wù)層
* @author ZNZ
*
*/public class ClazzService {
ClazzDaoInter dao = new ClazzDaoImpl();
/**
* 獲取指定年級下的班級
* @param gid 年級ID
* @return JSON格式的班級
*/
public String getClazzList(String gradeid){ int id = Integer.parseInt(gradeid); //獲取數(shù)據(jù)
List<Object> list = dao.getList(Clazz.class, "SELECT * FROM clazz WHERE gradeid=?", new Object[]{id}); //json化
JsonConfig config = new JsonConfig();
config.setExcludes(new String[]{"grade", "studentList"}); ? ? ? ?String result = JSONArray.fromObject(list, config).toString(); ? ? ? ?
? ? ? ?return result;
}
/**
* 獲取班級詳細(xì)信息
* @param gradeid
* @param page
* @return
*/
public String getClazzDetailList(String gradeid, Page page) { //獲取數(shù)據(jù)
List<Clazz> list = dao.getClazzDetailList(gradeid, page); //獲取總記錄數(shù)
long total = 0; if(!StringTool.isEmpty(gradeid)){ int gid = Integer.parseInt(gradeid);
total = dao.count("SELECT COUNT(*) FROM clazz WHERE gradeid=?", new Object[]{gid});
} else {
total = dao.count("SELECT COUNT(*) FROM clazz", new Object[]{});
} //定義Map
Map<String, Object> jsonMap = new HashMap<String, Object>(); ? //total鍵 存放總記錄數(shù),必須的
? ? ? ?jsonMap.put("total", total); ? ? ? ?//rows鍵 存放每頁記錄 list
? ? ? ?jsonMap.put("rows", list);
? ? ? ?//格式化Map,以json格式返回數(shù)據(jù)
? ? ? ?String result = JSONObject.fromObject(jsonMap).toString(); ? ? ? ?
? ? ? ?return result;
} /**
* 添加班級
* @param name
* @param gradeid
*/
public void addClazz(String name, String gradeid) { int gid = Integer.parseInt(gradeid);
dao.insert("INSERT INTO clazz(name, gradeid) value(?,?)", new Object[]{name, gid});
}
/**
* 刪除班級
* @param clazzid
* @throws Exception
*/
public void deleteClazz(int clazzid) throws Exception { //獲取連接
Connection conn = MysqlTool.getConnection(); try { //開啟事務(wù)
MysqlTool.startTransaction(); //刪除成績表
dao.deleteTransaction(conn, "DELETE FROM escore WHERE clazzid=?", new Object[]{clazzid}); //刪除考試記錄
dao.deleteTransaction(conn, "DELETE FROM exam WHERE clazzid=?", new Object[]{clazzid}); //刪除用戶
List<Object> list = dao.getList(Student.class, "SELECT number FROM student WHERE clazzid=?", ?new Object[]{clazzid}); if(list.size() > 0){
Object[] param = new Object[list.size()]; for(int i = 0;i < list.size();i++){ Student stu = (Student) list.get(i);
param[i] = stu.getNumber();
} String sql = "DELETE FROM user WHERE account IN ("+StringTool.getMark(list.size())+")";
dao.deleteTransaction(conn, sql, param); //刪除學(xué)生
dao.deleteTransaction(conn, "DELETE FROM student WHERE clazzid=?", new Object[]{clazzid});
} //刪除班級的課程和老師的關(guān)聯(lián)
dao.deleteTransaction(conn, "DELETE FROM clazz_course_teacher WHERE clazzid=?", new Object[]{clazzid}); //最后刪除班級
dao.deleteTransaction(conn, "DELETE FROM clazz WHERE id=?", ?new Object[]{clazzid});
//提交事務(wù)
MysqlTool.commit();
} catch (Exception e) { //回滾事務(wù)
MysqlTool.rollback();
e.printStackTrace(); throw e;
} finally {
MysqlTool.closeConnection();
}
}
}
package com.lizhou.service;import java.sql.Connection;import java.util.HashMap;import java.util.LinkedList;import java.util.List;import java.util.Map;import com.lizhou.bean.Clazz;import com.lizhou.bean.Course;import com.lizhou.bean.Grade;import com.lizhou.bean.Page;import com.lizhou.bean.Student;import com.lizhou.dao.impl.BaseDaoImpl;import com.lizhou.dao.impl.ClazzDaoImpl;import com.lizhou.dao.inter.BaseDaoInter;import com.lizhou.dao.inter.ClazzDaoInter;import com.lizhou.tools.MysqlTool;import com.lizhou.tools.StringTool;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import net.sf.json.JsonConfig;/**
* 課程服務(wù)層
* @author ZNZ
*
*/public class CourseService {
BaseDaoInter dao = new BaseDaoImpl();
/**
* 獲取所有課程
* @return
*/
public String getCourseList(String gradeid){
List<Object> list; if(StringTool.isEmpty(gradeid)){
list = dao.getList(Course.class, "SELECT * FROM course");
} else{
list = dao.getList(Course.class,
"SELECT c.* FROM course c, grade_course gc WHERE c.id=gc.courseid AND gc.gradeid=?",
new Object[]{Integer.parseInt(gradeid)});
} //json化
? ? ? ?String result = JSONArray.fromObject(list).toString(); ? ? ? ?
? ? ? ?return result;
} /**
* 添加課程
* @param course
*/
public void addCourse(Course course) {
dao.insert("INSERT INTO course(name) value(?)", new Object[]{course.getName()});
} /**
* 刪除課程
* @param courseid
* @throws Exception
*/
public void deleteClazz(int courseid) throws Exception { //獲取連接
Connection conn = MysqlTool.getConnection(); try { //開啟事務(wù)
MysqlTool.startTransaction(); //刪除成績表
dao.deleteTransaction(conn, "DELETE FROM escore WHERE courseid=?", new Object[]{courseid}); //刪除班級的課程和老師的關(guān)聯(lián)
dao.deleteTransaction(conn, "DELETE FROM clazz_course_teacher WHERE courseid=?", new Object[]{courseid}); //刪除年級與課程關(guān)聯(lián)
dao.deleteTransaction(conn, "DELETE FROM grade_course WHERE courseid=?", ?new Object[]{courseid}); //最后刪除課程
dao.deleteTransaction(conn, "DELETE FROM course WHERE id=?", ?new Object[]{courseid});
//提交事務(wù)
MysqlTool.commit();
} catch (Exception e) { //回滾事務(wù)
MysqlTool.rollback();
e.printStackTrace(); throw e;
} finally {
MysqlTool.closeConnection();
}
}
}
package com.lizhou.service;import java.sql.Connection;import java.util.HashMap;import java.util.LinkedList;import java.util.List;import java.util.Map;import com.lizhou.bean.Course;import com.lizhou.bean.CourseItem;import com.lizhou.bean.Exam;import com.lizhou.bean.Page;import com.lizhou.bean.Student;import com.lizhou.bean.Teacher;import com.lizhou.bean.User;import com.lizhou.dao.impl.BaseDaoImpl;import com.lizhou.dao.impl.ExamDaoImpl;import com.lizhou.dao.impl.StudentDaoImpl;import com.lizhou.dao.impl.TeacherDaoImpl;import com.lizhou.dao.inter.BaseDaoInter;import com.lizhou.dao.inter.ExamDaoInter;import com.lizhou.dao.inter.StudentDaoInter;import com.lizhou.dao.inter.TeacherDaoInter;import com.lizhou.tools.MysqlTool;import com.lizhou.tools.StringTool;import net.sf.json.JSONArray;import net.sf.json.JSONObject;/**
* 教師類服務(wù)層
* @author ZNZ
*
*/public class ExamService {
private ExamDaoInter dao;
public ExamService(){
dao = new ExamDaoImpl();
}
/**
* 獲取考試信息
* @param exam 參數(shù)
* @param page 分頁
* @return
*/
public String getExamList(Exam exam, Page page) { //sql語句
StringBuffer sb = new StringBuffer("SELECT * FROM exam "); //參數(shù)
List<Object> param = new LinkedList<>(); //判斷條件
if(exam != null){
if(exam.getGradeid() != 0){//條件:年級
int gradeid = exam.getGradeid();
param.add(gradeid);
sb.append("AND gradeid=? ");
} if(exam.getClazzid() != 0){ int clazzid = exam.getClazzid();
param.add(clazzid);
sb.append("AND clazzid=? ");
}
} //添加排序
sb.append("ORDER BY id DESC "); //分頁
if(page != null){
param.add(page.getStart());
param.add(page.getSize());
sb.append("LIMIT ?,?");
} String sql = sb.toString().replaceFirst("AND", "WHERE"); //獲取數(shù)據(jù)
List<Exam> list = dao.getExamList(sql, param); //獲取總記錄數(shù)
long total = getCount(exam); //定義Map
Map<String, Object> jsonMap = new HashMap<String, Object>(); ? //total鍵 存放總記錄數(shù),必須的
? ? ? ?jsonMap.put("total", total); ? ? ? ?//rows鍵 存放每頁記錄 list
? ? ? ?jsonMap.put("rows", list);
? ? ? ?//格式化Map,以json格式返回數(shù)據(jù)
? ? ? ?String result = JSONObject.fromObject(jsonMap).toString(); ? ? ? ?//返回
return result;
}
/**
* 獲取記錄數(shù)
* @param exam
* @return
*/
private long getCount(Exam exam){ //sql語句
StringBuffer sb = new StringBuffer("SELECT COUNT(*) FROM exam "); //參數(shù)
List<Object> param = new LinkedList<>(); //判斷條件
if(exam != null){
if(exam.getGrade() != null){//條件:年級
int gradeid = exam.getGradeid();
param.add(gradeid);
sb.append("AND gradeid=? ");
} if(exam.getClazz() != null){ int clazzid = exam.getClazzid();
param.add(clazzid);
sb.append("AND clazzid=? ");
}
} String sql = sb.toString().replaceFirst("AND", "WHERE");
long count = dao.count(sql, param).intValue();
return count;
}
/**
* 添加考試
* @param exam
* @throws Exception
*/
public void addExam(Exam exam) throws Exception { Connection conn = MysqlTool.getConnection(); try { //開啟事務(wù)
MysqlTool.startTransaction();
//添加考試信息
int examid = dao.insertReturnKeysTransaction(conn,
"INSERT INTO exam(name, time, remark, type, gradeid, clazzid, courseid) value(?,?,?,?,?,?,?)",
new Object[]{
exam.getName(),
exam.getTime(),
exam.getRemark(),
exam.getType(),
exam.getGradeid(),
exam.getClazzid(),
exam.getCourseid()
});
//添加學(xué)生成績表
String sql = "INSERT INTO escore(examid,clazzid,studentid,gradeid,courseid) value(?,?,?,?,?)";
if(exam.getType() == Exam.EXAM_GRADE_TYPE){ //年級統(tǒng)考
//查詢該年級的課程
List<Object> couObjList = dao.getList(Course.class,
"SELECT courseid id FROM grade_course WHERE gradeid=?",
new Object[]{exam.getGradeid()});
//查詢該年級下的學(xué)生
List<Object> stuList = dao.getList(Student.class,
"SELECT id, clazzid FROM student WHERE gradeid=?", new Object[]{exam.getGradeid()});
//轉(zhuǎn)換類型
List<Course> couList = new LinkedList<>(); for(Object obj : couObjList){ Course course = (Course) obj;
couList.add(course);
} //批量參數(shù)
Object[][] param = new Object[stuList.size()*couList.size()][5]; int index = 0; for(int i = 0;i < stuList.size();i++){ Student student = (Student) stuList.get(i); for(int j = 0;j < couList.size();j++){
param[index][0] = examid;
param[index][1] = student.getClazzid();
param[index][2] = student.getId();
param[index][3] = exam.getGradeid();
param[index][4] = couList.get(j).getId();
index++;
}
} //批量添加學(xué)生考試表
dao.insertBatchTransaction(conn, sql, param);
} else{ ?//平時考試
//查詢該班級下的學(xué)生
List<Object> stuList = dao.getList(Student.class,
"SELECT id FROM student WHERE clazzid=?", new Object[]{exam.getClazzid()});
//批量參數(shù)
Object[][] param = new Object[stuList.size()][5]; for(int i = 0;i < stuList.size();i++){ Student student = (Student) stuList.get(i);
param[i][0] = examid;
param[i][1] = exam.getClazzid();
param[i][2] = student.getId();
param[i][3] = exam.getGradeid();
param[i][4] = exam.getCourseid();
} //批量添加學(xué)生考試表
dao.insertBatchTransaction(conn, sql, param);
}
//提交事務(wù)
MysqlTool.commit();
} catch (Exception e) { //回滾事務(wù)
MysqlTool.rollback();
e.printStackTrace(); throw e;
} finally {
MysqlTool.closeConnection();
}
}
/**
* 刪除考試
* @param ids
* @throws Exception
*/
public void deleteExam(int id) throws Exception{ //獲取連接
Connection conn = MysqlTool.getConnection(); //開啟事務(wù)
MysqlTool.startTransaction(); try { //刪除成績表
dao.deleteTransaction(conn, "DELETE FROM escore WHERE examid=?", new Object[]{id}); //刪除考試
dao.deleteTransaction(conn, "DELETE FROM exam WHERE id =?", new Object[]{id});
//提交事務(wù)
MysqlTool.commit();
} catch (Exception e) { //回滾事務(wù)
MysqlTool.rollback();
e.printStackTrace(); throw e;
} finally {
MysqlTool.closeConnection();
}
} /**
* 獲取某老師的考試
* @param id
* @return
*/
public String teacherExamList(String number) { //獲取教師信息
Teacher teacher = new TeacherService().getTeacher(number);
List<CourseItem> itemList = teacher.getCourseList(); if(itemList.size() == 0){ return "";
} StringBuffer g = new StringBuffer(); StringBuffer c = new StringBuffer(); for(CourseItem item : itemList){
g.append(","+item.getGradeid());
c.append(","+item.getCourseid());
}
StringBuffer sb = new StringBuffer("SELECT * FROM exam WHERE (gradeid IN (");
sb.append(g.toString().replaceFirst(",", ""));
sb.append(") AND type=1) OR (courseid IN (");
sb.append(c.toString().replaceFirst(",", ""));
sb.append(") AND type=2)"); //sql語句
String sql = sb.toString(); //獲取數(shù)據(jù)
List<Exam> list = dao.getExamList(sql, null);
? ? ? ?//格式化Map,以json格式返回數(shù)據(jù)
? ? ? ?String result = JSONArray.fromObject(list).toString(); ? ? ? ?//返回
return result;
}
/**
* 獲取某個學(xué)生考試列表
* @param number
* @return
*/
public String studentExamList(String number) {
//獲取學(xué)生詳細(xì)信息
Student student = new StudentDaoImpl().getStudentList("SELECT * FROM student WHERE number="+number, null).get(0);
String sql = "SELECT * FROM exam WHERE (gradeid=? AND type=1) OR (clazzid=? AND type=2)";
List<Object> param = new LinkedList<>();
param.add(student.getGradeid());
param.add(student.getClazzid());
//獲取數(shù)據(jù)
List<Exam> list = dao.getExamList(sql, param);
//格式化Map,以json格式返回數(shù)據(jù)
? ? ? ?String result = JSONArray.fromObject(list).toString();
return result;
}
}