作者主页:夜未央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版本;
技术栈
HTML+CSS+JavaScript+jsp+mysql
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/login.jsp 登录
运行截图
相关代码
成绩管理控制器
@Controller
@RequestMapping("/scoreController")
public class ScoreController extends BaseController {
private static final Logger logger = Logger.getLogger(ScoreController.class);
String[] excelHeader = { "学生学号", "课程名称", "分数", "学期", "班级", "教师工号","教师姓名", "学生姓名"};
@Autowired
private ScoreService scoreService;
/**
* 初始访问
*
* @param
* @param model
* @return
*/
@RequestMapping(params = "goScore")
public ModelAndView goScore(HttpServletRequest request) {
return new ModelAndView("buss/score");
}
@RequestMapping(params = "save")
@ResponseBody
public AjaxJson save(HttpServletRequest request, HttpServletResponse response, ScoreEntity scoreEntity,
String studentid, String teacherid) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("保存成功!");
j.setSuccess(true);
try {
TeacherEntity teacher = this.scoreService.get(TeacherEntity.class, teacherid);
StudentEntity student = this.scoreService.get(StudentEntity.class, studentid);
scoreEntity.setTeacherEntity(teacher);
scoreEntity.setStudentEntity(student);
this.scoreService.save(scoreEntity);
} catch (Exception e) {
j.setMsg("保存失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params = "update")
@ResponseBody
public AjaxJson update(HttpServletRequest request, HttpServletResponse response, ScoreEntity scoreEntity,
String studentid, String teacherid) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("更新成功!");
j.setSuccess(true);
try {
TeacherEntity teacher = this.scoreService.get(TeacherEntity.class, teacherid);
StudentEntity student = this.scoreService.get(StudentEntity.class, studentid);
scoreEntity.setTeacherEntity(teacher);
scoreEntity.setStudentEntity(student);
this.scoreService.update(scoreEntity);
} catch (Exception e) {
j.setMsg("更新失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params = "delete", method = RequestMethod.POST)
@ResponseBody
public AjaxJson delete(HttpServletRequest request, HttpServletResponse response, String ids) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("删除成功!");
j.setSuccess(true);
try {
for (String id : ids.split(",")) {
ScoreEntity scoreEntity = new ScoreEntity();
scoreEntity.setId(id);
this.scoreService.delete(scoreEntity);
}
} catch (Exception e) {
j.setMsg("删除失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params = "uploadScore", method = RequestMethod.POST)
@ResponseBody
public AjaxJson uploadScore(@RequestParam("scoreExcel") MultipartFile scoreExcel) {
AjaxJson j = new AjaxJson();
j.setMsg("导入成功!");
j.setSuccess(true);
try {
if (!scoreExcel.isEmpty()) {
InputStream is = scoreExcel.getInputStream();
String[] fileName = scoreExcel.getOriginalFilename().split("\\.");
List<ScoreEntity> scoreList = new ArrayList<ScoreEntity>();
// 判断excel版本
if ("xls".equals(fileName[1])) {
// List<String> results =
// ExcelImportUtil.getExcelStringList(is);
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
for (int i = 0; i < hssfWorkbook.getNumberOfSheets(); i++) {
HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(i);
if (hssfSheet == null) {
continue;
}
// 循环行Row
for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
HSSFRow hssfRow = hssfSheet.getRow(rowNum);
if (hssfRow != null) {
ScoreEntity se = new ScoreEntity();
TeacherEntity te = new TeacherEntity();
StudentEntity stu = new StudentEntity();
HSSFCell stuNum = hssfRow.getCell(0);
HSSFCell courseName = hssfRow.getCell(1);
HSSFCell score = hssfRow.getCell(2);
HSSFCell term = hssfRow.getCell(3);
HSSFCell className = hssfRow.getCell(4);
HSSFCell teacherNum = hssfRow.getCell(5);
int stuInt = (int) stuNum.getNumericCellValue();
int teacherInt = (int) teacherNum.getNumericCellValue();
te = this.scoreService.findUniqueByProperty(TeacherEntity.class, "teachernum",
String.valueOf(teacherInt));
stu = this.scoreService.findUniqueByProperty(StudentEntity.class, "studentnum",
String.valueOf(stuInt));
BigDecimal bd = new BigDecimal(score.getNumericCellValue());
se.setTeacherEntity(te);
se.setStudentEntity(stu);
se.setClassname(className.getStringCellValue());
se.setCoursename(courseName.getStringCellValue());
se.setScore(bd);
se.setTerm(term.getStringCellValue());
scoreList.add(se);
}
}
}
} else if ("xlsx".equals(fileName[1])) {
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
// Read the Row
for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
XSSFRow xssfRow = xssfSheet.getRow(rowNum);
if (xssfRow != null) {
ScoreEntity se = new ScoreEntity();
TeacherEntity te = new TeacherEntity();
StudentEntity stu = new StudentEntity();
XSSFCell stuNum = xssfRow.getCell(0);
XSSFCell courseName = xssfRow.getCell(1);
XSSFCell score = xssfRow.getCell(2);
XSSFCell term = xssfRow.getCell(3);
XSSFCell className = xssfRow.getCell(4);
XSSFCell teacherNum = xssfRow.getCell(5);
int stuInt = (int) stuNum.getNumericCellValue();
int teacherInt = (int) teacherNum.getNumericCellValue();
te = this.scoreService.findUniqueByProperty(TeacherEntity.class, "teachernum",
String.valueOf(teacherInt));
stu = this.scoreService.findUniqueByProperty(StudentEntity.class, "studentnum",
String.valueOf(stuInt));
BigDecimal bd = new BigDecimal(score.getNumericCellValue());
se.setTeacherEntity(te);
se.setStudentEntity(stu);
se.setClassname(className.getStringCellValue());
se.setCoursename(courseName.getStringCellValue());
se.setScore(bd);
se.setTerm(term.getStringCellValue());
scoreList.add(se);
}
}
}
}else{
j.setMsg("请导入正确的excel文件!");
j.setSuccess(false);
}
this.scoreService.saveBatch(scoreList);
}
} catch (Exception e) {
e.printStackTrace();
j.setMsg("导入失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params = "exportExcel")
public void exportExcel(HttpServletRequest request, HttpServletResponse response,String teachername,String coursename,
String term,String name) throws Exception {
DetachedCriteria condition = DetachedCriteria.forClass(ScoreEntity.class);
List<ScoreEntity> scoreList = this.scoreService.findData(condition, name, teachername, coursename, term);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheet1");
HSSFRow row = sheet.createRow((int) 0);
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
for (int i = 0; i < excelHeader.length; i++) {
HSSFCell cell = row.createCell(i);
cell.setCellValue(excelHeader[i]);
cell.setCellStyle(style);
sheet.autoSizeColumn(i);
}
for (int i = 0; i < scoreList.size(); i++) {
row = sheet.createRow(i + 1);
ScoreEntity scoreEntity = scoreList.get(i);
row.createCell(0).setCellValue(scoreEntity.getStudentEntity().getStudentnum());
row.createCell(1).setCellValue(scoreEntity.getCoursename());
row.createCell(2).setCellValue(scoreEntity.getScore().toString());
row.createCell(3).setCellValue(scoreEntity.getTerm());
row.createCell(4).setCellValue(scoreEntity.getClassname());
row.createCell(5).setCellValue(scoreEntity.getTeacherEntity().getTeachernum());
row.createCell(6).setCellValue(scoreEntity.getTeacherEntity().getTeachername());
row.createCell(7).setCellValue(scoreEntity.getStudentEntity().getName());
}
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment;filename=studentScore.xls");
OutputStream ouputStream = response.getOutputStream();
try{
wb.write(ouputStream);
ouputStream.flush();
ouputStream.close();
}catch(Exception e){
e.printStackTrace();
}finally{
ouputStream.flush();
ouputStream.close();
}
}
@RequestMapping(params = "datagrid")
@ResponseBody
public void datagrid(HttpServletRequest request, HttpServletResponse response, ScoreEntity ve, String name,
String teachername, String coursename, String term) throws Exception {
String page = request.getParameter("page");// easyui datagrid 分页 页号
String rows = request.getParameter("rows");// easyui datagrid 分页 页数
if (page == null) {
page = "0";
}
if (rows == null) {
rows = "0";
}
DetachedCriteria condition = DetachedCriteria.forClass(ScoreEntity.class);
Pagination<?> pagination = scoreService.findPageData(condition, ve, Integer.parseInt(page),
Integer.parseInt(rows), name, teachername, coursename, term);
JSONObject jobj = new JSONObject();
jobj.put("total", pagination.getTotalCount());
jobj.put("rows", pagination.getDatas());
response.setCharacterEncoding("utf-8");
response.getWriter().write(jobj.toString());
}
}
学生管理控制器
@Controller
@RequestMapping("/studentController")
public class StudentController extends BaseController{
private static final Logger logger = Logger.getLogger(StudentController.class);
@Autowired
private StudentService studentService;
/**
* 初始访问
* @param
* @param model
* @return
*/
@RequestMapping(params="goStudent")
public ModelAndView goStudent(HttpServletRequest request){
return new ModelAndView("buss/student");
}
@RequestMapping(params="checkNum")
@ResponseBody
public void checkNum(HttpServletRequest request, HttpServletResponse response, String studentNum) throws Exception {
StudentEntity student = this.studentService.findUniqueByProperty(StudentEntity.class, "studentnum", studentNum);
String flag = "true";
if(student != null){
flag = "false";
}
response.setCharacterEncoding("utf-8");
response.getWriter().write(flag);
}
@RequestMapping(params="save")
@ResponseBody
public AjaxJson save(HttpServletRequest request, HttpServletResponse response, StudentEntity student) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("保存成功!");
j.setSuccess(true);
try{
this.studentService.save(student);
}catch(Exception e){
j.setMsg("保存失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params="update")
@ResponseBody
public AjaxJson update(HttpServletRequest request, HttpServletResponse response, StudentEntity student) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("更新成功!");
j.setSuccess(true);
try{
// StudentEntity se = this.studentService.get(StudentEntity.class, student.getId());
this.studentService.update(student);
}catch(Exception e){
j.setMsg("更新失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params="delete",method=RequestMethod.POST)
@ResponseBody
public AjaxJson delete(HttpServletRequest request, HttpServletResponse response, String ids) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("删除成功!");
j.setSuccess(true);
try{
for(String id:ids.split(",")){
StudentEntity student = this.studentService.get(StudentEntity.class, id);
this.studentService.delete(student);
}
}catch(ConstraintViolationException ce){
ce.printStackTrace();
j.setMsg("删除失败,存在外键引用,请查看其它数据项中是否有与当前数据有关的信息!");
j.setSuccess(false);
}catch(Exception e){
j.setMsg("删除失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params="datagrid")
@ResponseBody
public void datagrid(HttpServletRequest request, HttpServletResponse response,StudentEntity student) throws Exception {
String page = request.getParameter("page");
String rows = request.getParameter("rows");
if(page == null){
page = "0";
}
if(rows == null){
rows = "0";
}
DetachedCriteria condition = DetachedCriteria.forClass(StudentEntity.class);
Pagination<?> pagination = studentService.findPageData(condition,student,Integer.parseInt(page), Integer.parseInt(rows));
JSONObject jobj = new JSONObject();
jobj.put("total", pagination.getTotalCount());
jobj.put("rows", pagination.getDatas());
response.setCharacterEncoding("utf-8");
response.getWriter().write(jobj.toString());
}
}
教师管理控制器
@Controller
@RequestMapping("/teacherController")
public class TeacherController extends BaseController{
private static final Logger logger = Logger.getLogger(TeacherController.class);
@Autowired
private TeacherService teacherService;
/**
* 初始访问
* @param
* @param model
* @return
*/
@RequestMapping(params="goTeacher")
public ModelAndView goTeacher(HttpServletRequest request){
return new ModelAndView("buss/teacher");
}
@RequestMapping(params="checkTeachernum")
@ResponseBody
public void checkTeachernum(HttpServletRequest request, HttpServletResponse response, String teacherNum) throws Exception {
TeacherEntity teacher = this.teacherService.findUniqueByProperty(TeacherEntity.class, "teachernum", teacherNum);
String flag = "true";
if(teacher != null){
flag = "false";
}
response.setCharacterEncoding("utf-8");
response.getWriter().write(flag);
}
@RequestMapping(params="save")
@ResponseBody
public AjaxJson save(HttpServletRequest request, HttpServletResponse response, TeacherEntity teacherEntity) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("保存成功!");
j.setSuccess(true);
try{
this.teacherService.save(teacherEntity);
}catch(Exception e){
j.setMsg("保存失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params="update")
@ResponseBody
public AjaxJson update(HttpServletRequest request, HttpServletResponse response, TeacherEntity teacherEntity) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("更新成功!");
j.setSuccess(true);
try{
this.teacherService.update(teacherEntity);
}catch(Exception e){
j.setMsg("更新失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params="delete",method=RequestMethod.POST)
@ResponseBody
public AjaxJson delete(HttpServletRequest request, HttpServletResponse response, String ids) throws Exception {
AjaxJson j = new AjaxJson();
j.setMsg("删除成功!");
j.setSuccess(true);
try{
for(String id:ids.split(",")){
TeacherEntity teacherEntity = new TeacherEntity();
teacherEntity = teacherService.get(TeacherEntity.class, id);
this.teacherService.delete(teacherEntity);
}
}catch(Exception e){
j.setMsg("删除失败!");
j.setSuccess(false);
}
return j;
}
@RequestMapping(params="datagrid")
@ResponseBody
public void datagrid(HttpServletRequest request, HttpServletResponse response, TeacherEntity ve) throws Exception {
String page = request.getParameter("page");//easyui datagrid 分页 页号
String rows = request.getParameter("rows");//easyui datagrid 分页 页数
if(page == null){
page = "0";
}
if(rows == null){
rows = "0";
}
DetachedCriteria condition = DetachedCriteria.forClass(TeacherEntity.class);
Pagination<?> pagination = teacherService.findPageData(condition,ve,Integer.parseInt(page), Integer.parseInt(rows));
JSONObject jobj = new JSONObject();
jobj.put("total", pagination.getTotalCount());
jobj.put("rows", pagination.getDatas());
response.setCharacterEncoding("utf-8");
response.getWriter().write(jobj.toString());
}
}
如果也想学习本系统,下面领取。关注并回复:054jsp