作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目包含管理员、教师、学生三种角色;
用户角色包含以下功能:
修改密码,查看自己的信息,查看自己的成绩,登录界面等功能。
管理员角色包含以下功能:
修改示例,增删改查学生信息,增删改查教师信息,增删改查课程信息,管理员修改密码等功能。
老师角色包含以下功能:
个人信息查看,修改成绩信息,增加成绩信息,管理学生成绩信息等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;
技术栈
JSP+CSS+JavaScript+jquery+bootstrap+servlet+mysql
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中dbconfig.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入http://localhost:8080/ 登录
管理员账号/密码:admin/admin
教师账号/密码: 20194101/123456
学生账号/密码: 202041404237/123456
运行截图
登录界面
管理员角色
教师角色
学生角色
相关代码
TeacherDao
package com.dgut.sc.dao;
import java.util.List;
import com.dgut.sc.domain.Teacher;
public interface TeacherDao {
/**
* 增加一条教师信息
*
* @param student
* @return
*/
boolean addTeacher(Teacher teacher);
/**
* 删除一条教师信息
*
* @param sno
* @return
*/
boolean deleteTeacher(String tno);
/**
* 更新一条教师信息
*
* @param student
* @return
*/
boolean updateTeacher(Teacher teacher);
/**
* 查询所有教师信息
*
* @return
*/
List<Teacher> queryAllTeacher(int startIndex, int pagesize);
/**
* 查询一条教师信息
*
* @param sno
* @return
*/
Teacher queryTeacher(String tno);
/**
* 查询一条教师信息
*
* @param sno
* @return
*/
Teacher queryTeacher(String tno, String password);
/**
* 更新一条教师密码
*
* @param tno
* @param password
* @return
*/
boolean updateTeacherPwd(String tno, String password);
int getAllTeacherCounts();
}
StudentDao
package com.dgut.sc.dao;
import java.util.List;
import com.dgut.sc.domain.Student;
public interface StudentDao {
/**
* 增加一条学生信息
* @param student
* @return
*/
boolean addStudent(Student student);
/**
* 删除一条学生信息
* @param sno
* @return
*/
boolean deleteStudent(String sno);
/**
* 更新一条学生密码
* @param sno
* @param password
* @return
*/
boolean updateStudentPwd(String sno,String password);
/**
* 更新一条学生信息
* @param sno
* @param password
* @param sname
* @param sex
* @param major
* @param department
* @param sclass
* @return
*/
boolean updateStudent(String sno,String password,String sname,String sex,String major,String department,String sclass);
/**
* 查询所有学生信息
* @return
*/
List<Student> queryAllStudent(int startIndex, int pagesize);
/**
* 查询一条学生信息
* @param sno
* @return
*/
Student queryStudent(String sno,String password);
/**
* 查询一条学生信息
* @param sno
* @return
*/
public Student queryStudent(String sno);
/**
* 获取学生总数
* @return
*/
public int getAllStudentCounts() ;
}
package com.dgut.sc.dao;
import java.util.List;
import com.dgut.sc.domain.Score;
public interface ScoreDao {
/**
* 增加一条成绩信息
*
* @param student
* @return
*/
boolean addScore(Score score);
/**
* 删除一条成绩信息
*
* @param sno
* @return
*/
boolean deleteScore(String sno, String cno);
/**
* 更新一条成绩信息
*
* @param student
* @return
*/
boolean updateScore(Score score);
/**
* 更新一条成绩信息
*
* @param student
* @return
*/
boolean updateScore(String sno, String cno, String grade,
String get_credit, String gPA, String credit_GPA);
/**
* 查询所有成绩信息
*
* @return
*/
List<Score> queryAllScore(int startIndex, int pagesize);
/**
* 查询某个人所有成绩信息
*
* @return
*/
List<Score> queryAllScoreBySno(String sno, int startIndex, int pagesize);
/**
* 查询一条成绩信息
*
* @param sno
* @return
*/
Score queryScore(String sno, String cno);
/**
* 得到成绩记录总数
*
* @return
*/
int getAllScoreCounts();
List<Score> queryAllScoreByTno(String tno, int startIndex, int pageSize);
int getAllScoreCountsByTno(String tno);
int getAllScoreCountsBySno(String sno);
}
AdminDaoImpl
package com.dgut.sc.dao.impl;
import java.sql.SQLException;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import com.dgut.sc.dao.AdminDao;
import com.dgut.sc.domain.Admin;
import com.sc.util.DBCPUtil;
public class AdminDaoImpl implements AdminDao {
QueryRunner qr = new QueryRunner(DBCPUtil.getDataSource());
@Override
public boolean updateAdmin(String admin,String password) {
try {
int num = qr.update("update admin set password=? where admin=?",
password, admin);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public Admin queryAdmin(String admin) {
try {
return qr.query("select * from admin where admin=?",
new BeanHandler<Admin>(Admin.class), admin);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public Admin queryAdmin(String admin, String password) {
try {
return qr.query("select * from admin where admin=? and password=?",
new BeanHandler<Admin>(Admin.class), admin, password);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}
package com.dgut.sc.dao.impl;
import java.sql.SQLException;
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 org.apache.commons.dbutils.handlers.ScalarHandler;
import com.dgut.sc.dao.CourseDao;
import com.dgut.sc.domain.Course;
import com.dgut.sc.domain.Teacher;
import com.sc.util.DBCPUtil;
public class CourseDaoImpl implements CourseDao {
QueryRunner qr = new QueryRunner(DBCPUtil.getDataSource());
@Override
public boolean addCourse(Course course) {
try {
qr.update(
"insert into course (cno,cname,tno,tname,credit) values(?,?,?,?,?)",
course.getCno(), course.getCname(), course.getTno(),
course.getTname(), course.getCredit());
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean deleteCourse(String cno) {
try {
int num = qr.update("delete from course where cno=?", cno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean updateCourse(Course course) {
try {
int num = qr
.update("update course set cname=?,tno=?,tname=?,credit=? where cno=?",
course.getCname(), course.getTno(),
course.getTname(), course.getCredit(),course.getCno());
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public Course queryCourse(String cno) {
try {
return qr.query("select * from course where cno=? ",
new BeanHandler<Course>(Course.class), cno);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public List<Course> queryAllCourse(int startIndex, int pagesize) {
try {
return qr.query("select * from course order by cno asc limit ?,?",
new BeanListHandler<Course>(Course.class), startIndex,
pagesize);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public int getAllCourseCounts() {
try {
Long num = (Long) qr.query("select count(*) from course ",
new ScalarHandler(1));
return num.intValue();
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
}
package com.dgut.sc.dao.impl;
import java.sql.SQLException;
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 org.apache.commons.dbutils.handlers.ScalarHandler;
import com.dgut.sc.dao.ScoreDao;
import com.dgut.sc.domain.Score;
import com.dgut.sc.domain.Student;
import com.sc.util.DBCPUtil;
public class ScoreDaoImpl implements ScoreDao {
QueryRunner qr = new QueryRunner(DBCPUtil.getDataSource());
@Override
public boolean addScore(Score score) {
try {
qr.update(
"insert into score (sno,sname,cno,cname,credit,type,exam_method,property,grade,get_credit,GPA,credit_GPA,note,tno) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
score.getSno(), score.getSname(), score.getCno(),
score.getCname(), score.getCredit(), score.getType(),
score.getExam_method(), score.getProperty(),
score.getGrade(), score.getGet_credit(), score.getGPA(),
score.getCredit_GPA(), score.getNote(), score.getTno());
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean deleteScore(String sno, String cno) {
try {
int num = qr.update("delete from score where cno=? and sno=?", cno,
sno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean updateScore(Score score) {
try {
int num = qr
.update("update score set grade=?,get_credit=?,GPA=?,credit_GPA=? where cno=? and sno=?",
score.getGrade(), score.getGet_credit(),
score.getGPA(), score.getCredit_GPA(),
score.getCno(), score.getSno());
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public List<Score> queryAllScore(int startIndex, int pagesize) {
try {
return qr.query("select * from score order by sno desc limit ?,?",
new BeanListHandler<Score>(Score.class), startIndex,
pagesize);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public Score queryScore(String sno, String cno) {
try {
return qr.query("select * from score where sno=? and cno=?",
new BeanHandler<Score>(Score.class), sno, cno);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public int getAllScoreCounts() {
try {
Long num = (Long) qr.query("select count(*) from score ",
new ScalarHandler(1));
return num.intValue();
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
public int getAllScoreCountsBySno(String sno) {
try {
Long num = (Long) qr.query(
"select count(*) from score where sno=?",
new ScalarHandler(1),sno);
return num.intValue();
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
@Override
public List<Score> queryAllScoreBySno(String sno, int startIndex,
int pagesize) {
try {
return qr
.query("select * from score where sno = ? order by cno asc limit ?,?",
new BeanListHandler<Score>(Score.class), sno,
startIndex, pagesize);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public int getAllScoreCountsByTno(String tno) {
try {
Long num = (Long) qr.query(
"select count(*) from score where tno=?",
new ScalarHandler(1), tno);
return num.intValue();
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
@Override
public List<Score> queryAllScoreByTno(String tno, int startIndex,
int pageSize) {
try {
return qr
.query("select * from score where tno = ? order by cno asc limit ?,?",
new BeanListHandler<Score>(Score.class), tno,
startIndex, pageSize);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public boolean updateScore(String sno, String cno, String grade,
String get_credit, String gPA, String credit_GPA) {
try {
int num = qr
.update("update score set grade=?,get_credit=?,GPA=?,credit_GPA=? where sno=? and cno=?",
grade, get_credit, gPA, credit_GPA, sno, cno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
}
package com.dgut.sc.dao.impl;
import java.sql.SQLException;
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 org.apache.commons.dbutils.handlers.ScalarHandler;
import com.dgut.sc.dao.StudentDao;
import com.dgut.sc.domain.Student;
import com.sc.util.DBCPUtil;
public class StudentDaoImpl implements StudentDao {
QueryRunner qr = new QueryRunner(DBCPUtil.getDataSource());
@Override
public boolean addStudent(Student student) {
try {
qr.update(
"insert into student (sno,sname,password,sex,major,department,sclass) values(?,?,?,?,?,?,?)",
student.getSno(), student.getSname(),
student.getPassword(), student.getSex(),
student.getMajor(), student.getDepartment(),
student.getSclass());
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean deleteStudent(String sno) {
try {
int num = qr.update("delete from student where sno=?", sno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean updateStudentPwd(String sno, String password) {
try {
int num = qr.update("update student set password=? where sno=?",
password, sno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public List<Student> queryAllStudent(int startIndex, int pagesize) {
try {
return qr.query(
"select * from student order by sno asc limit ?,?",
new BeanListHandler<Student>(Student.class), startIndex,
pagesize);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public Student queryStudent(String sno, String password) {
try {
return qr.query("select * from student where sno=? and password=?",
new BeanHandler<Student>(Student.class), sno, password);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
public int getAllStudentCounts() {
try {
Long num = (Long)qr.query("select count(*) from student ",new ScalarHandler(1));
return num.intValue();
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
@Override
public Student queryStudent(String sno) {
try {
return qr.query("select * from student where sno=? ",
new BeanHandler<Student>(Student.class), sno);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public boolean updateStudent(String sno, String password, String sname,
String sex, String major, String department, String sclass) {
try {
int num = qr.update("update student set sname=?,password=?,sex=?,major=?,department=?,sclass=? where sno=?",
sname,password, sex,major,department,sclass,sno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
}
package com.dgut.sc.dao.impl;
import java.sql.SQLException;
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 org.apache.commons.dbutils.handlers.ScalarHandler;
import com.dgut.sc.dao.TeacherDao;
import com.dgut.sc.domain.Teacher;
import com.sc.util.DBCPUtil;
public class TeacherDaoImpl implements TeacherDao {
QueryRunner qr = new QueryRunner(DBCPUtil.getDataSource());
@Override
public boolean addTeacher(Teacher teacher) {
try {
qr.update(
"insert into teacher (tno,tname,password,sex,department,degree,title) values(?,?,?,?,?,?,?)",
teacher.getTno(), teacher.getTname(),
teacher.getPassword(), teacher.getSex(),
teacher.getDepartment(), teacher.getDegree(),
teacher.getTitle());
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean deleteTeacher(String tno) {
try {
int num = qr.update("delete from teacher where tno=?", tno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean updateTeacher(Teacher teacher) {
try {
int num = qr
.update("update teacher set tname=?,password=?,sex=?,department=?,degree=?,title=? where tno=?",
teacher.getTname(), teacher.getPassword(),
teacher.getSex(), teacher.getDepartment(),
teacher.getDegree(), teacher.getTitle(),teacher.getTno());
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
@Override
public List<Teacher> queryAllTeacher(int startIndex, int pagesize) {
try {
return qr.query("select * from teacher order by tno asc limit ?,?",
new BeanListHandler<Teacher>(Teacher.class), startIndex,
pagesize);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public Teacher queryTeacher(String tno) {
try {
return qr.query("select * from teacher where tno=? ",
new BeanHandler<Teacher>(Teacher.class), tno);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public int getAllTeacherCounts() {
try {
Long num = (Long) qr.query("select count(*) from teacher ",
new ScalarHandler(1));
return num.intValue();
} catch (SQLException e) {
e.printStackTrace();
return -1;
}
}
@Override
public Teacher queryTeacher(String tno, String password) {
try {
return qr.query("select * from teacher where tno=? and password=?",
new BeanHandler<Teacher>(Teacher.class), tno, password);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
@Override
public boolean updateTeacherPwd(String tno, String password) {
try {
int num = qr.update("update teacher set password=? where tno=?",
password, tno);
return num == 1;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
}
如果也想学习本系统,下面领取。关注并回复:045jsp