源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目分为管理员角色与学生两种角色;
管理员主要功能包括:
权限管理:用户管理、角色管理、菜单管理;
学生管理:成绩管理、学生信息管理、学籍管理、奖惩管理;
修改密码等;
学生主要功能包括:
学生管理:成绩管理、学生信息管理、学籍管理、奖惩管理;
环境需要
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项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
技术栈
1. 后端:spring springmvc mybatis
2. 前端:JSP+Html+css+javascript+bootstrap+jQuery+easyUI
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中applicationContext.xml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
学生管理控制层:
@Controller
@RequestMapping(value="/student")
public class StudentController {
@Autowired
private StudentService studentService;
@ResponseBody
@RequestMapping(value="/list")
public String getStudentList(@RequestParam(defaultValue="0")int curr,
@RequestParam(defaultValue="20")int nums,
@RequestParam(defaultValue="")String searchKey) {
Pagination<Student> page = new Pagination<Student>();
page.setTotalItemsCount(studentService.getTotalItemsCount(searchKey));
page.setPageSize(nums);
page.setPageNum(curr);
List<Student> list = studentService.getStudentList(page,searchKey);
String jsonStr = StrUtil.RETURN_JONS_PRE_STR
+ page.getTotalItemsCount()
+ StrUtil.RETURN_JONS_MID_STR
+ JSON.toJSONString(list)
+ StrUtil.RETURN_JONS_END_STR;
return jsonStr;
}
/**
* 返回选修了我课程的学生列表
* @return
*/
@ResponseBody
@RequestMapping(value="/stulist")
public String getMyStudentList(@RequestParam(defaultValue="0")int curr,
@RequestParam(defaultValue="20")int nums,
@RequestParam(required=false) Integer cId, HttpSession session) {
Teacher t = (Teacher) session.getAttribute(StrUtil.USER);
Pagination<Student> page = new Pagination<Student>();
page.setTotalItemsCount(studentService.getTotalItemsCountByTid(t.getId(), cId));
page.setPageSize(nums);
page.setPageNum(curr);
List<Student> list = studentService.getStudentListByTid(page, t.getId(), cId);
String jsonStr = StrUtil.RETURN_JONS_PRE_STR
+ page.getTotalItemsCount()
+ StrUtil.RETURN_JONS_MID_STR
+ JSON.toJSONString(list)
+ StrUtil.RETURN_JONS_END_STR;
System.out.println(jsonStr);
return jsonStr;
}
@RequestMapping(value="/addPage")
public ModelAndView toAddPage() {
return new ModelAndView("/studentAdd");
}
/**
* 增加,或者修改studnet
* @param opType
* @param stu
* @return
*/
@ResponseBody
@RequestMapping(value="/add")
public String addStudent(@RequestParam(defaultValue="2") int opType, Student stu) {
int res = 0;
if (opType == 0) {
try {
stu.setPassword(stu.getPassword().toUpperCase());
res = studentService.addStudent(stu);
} catch (Exception e) {
System.out.println("添加失败!学号重复!");
return "添加失败!学号重复!";
}
if (res > 0)
return StrUtil.RESULT_TRUE;
return "添加失败";
} else if (opType == 1) {
stu.setPassword(null);
res = studentService.updateStudent(stu);
if (res > 0) return StrUtil.RESULT_TRUE;
return "修改失败!";
}
return "error";
}
/**
* 重置密码
* @param stu
* @return
*/
@ResponseBody
@RequestMapping(value="/resetPswd")
public String resetPasswrd(String id) {
Student stu = new Student();
stu.setId(id);
stu.setPassword(MD5Util.MD5("123456"));
if (studentService.updateStudent(stu) > 0) return StrUtil.RESULT_TRUE;
return "修改失败!";
}
@ResponseBody
@RequestMapping(value="/delete")
public String deleteStudnet(Student stu) {
if (studentService.deleteStudent(stu) > 0) return StrUtil.RESULT_TRUE;
return "删除失败!";
}
/**
* 批量删除
* @param stuIds
* @return
*/
@ResponseBody
@RequestMapping(value="/deleteList")
public String deleteStudnetList(String stuIds) {
List<String> list = new ArrayList<String>();
try {
String[] ids = stuIds.split(",");
for (String id: ids) {
list.add(id);
}
if (studentService.deleteStudent(list) > 0) {
return StrUtil.RESULT_TRUE;
}
} catch (Exception e) {
e.printStackTrace();
return "删除失败!参数出错!";//
}
return "删除失败!";
}
@ResponseBody
@RequestMapping("/import")
public String impotr(HttpServletRequest request, MultipartFile file) {
//获取上传的文件
InputStream in = null;
try {
in = file.getInputStream();
//数据导入
int res = studentService.importExcelInfo(in,file);
if (res > 0) {
return StrUtil.RETURN_JONS_PRE_STR+"0"
+StrUtil.RETURN_JONS_MID_STR+"true"
+StrUtil.RETURN_JONS_END_STR;
} else {
return StrUtil.RETURN_JONS_PRE_STR+"0"
+StrUtil.RETURN_JONS_MID_STR+"false"
+StrUtil.RETURN_JONS_END_STR;
}
} catch (Exception e) {
e.printStackTrace();
return StrUtil.RETURN_JONS_PRE_STR+"0"
+StrUtil.RETURN_JONS_MID_STR+"error"
+StrUtil.RETURN_JONS_END_STR;
} finally {
if (in != null)
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@RequestMapping(value="/courses")
public ModelAndView toChoiceCoursePage() {
return new ModelAndView("choiceCourse");
}
}
成绩管理控制层:
@Controller
@RequestMapping(value="/score")
public class ScoreController {
@Autowired
private ScoreService scoreService;
@ResponseBody
@RequestMapping(value="/list")
public String getScoreList(Integer curr, Integer nums, ScoreVo scoreVo) {
System.out.println(scoreVo);
Pagination<ScoreVo> page = new Pagination<ScoreVo>();
page.setTotalItemsCount(scoreService.getTotalItemsCount(scoreVo));
page.setPageSize(nums);
page.setPageNum(curr);
List<ScoreVo> list = scoreService.getScoreList(page, scoreVo);
String jsonStr = StrUtil.RETURN_JONS_PRE_STR
+ page.getTotalItemsCount()
+ StrUtil.RETURN_JONS_MID_STR
+ JSON.toJSONString(list)
+ StrUtil.RETURN_JONS_END_STR;
System.out.println(jsonStr);
return jsonStr;
}
@ResponseBody
@RequestMapping("/export")
public void export(HttpServletRequest request, HttpServletResponse response, ScoreVo scoreVo)
throws ClassNotFoundException, IntrospectionException,
IllegalAccessException, ParseException, InvocationTargetException {
response.reset(); // 清除buffer缓存
// 设置文件名
response.setHeader("Content-Disposition", "attachment;filename="
+ System.currentTimeMillis() + ".xls");
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
XSSFWorkbook workbook = null;
// 导出Excel对象
workbook = scoreService.exportExcelInfo(scoreVo);
OutputStream output;
try {
output = response.getOutputStream();
BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
bufferedOutPut.flush();
workbook.write(bufferedOutPut);
bufferedOutPut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 学生查成绩列表
* @param curr
* @param nums
* @param searchKey
* @return
*/
@ResponseBody
@RequestMapping(value="/stuScore")
public String getScoreList(@RequestParam(defaultValue="0")int curr,
@RequestParam(defaultValue="20")int nums,
HttpSession session, Integer result) {
Student stu = (Student) session.getAttribute(StrUtil.USER);
Pagination<Course> page = new Pagination<Course>();
page.setTotalItemsCount(scoreService.getTotalItemsCount(stu.getId(), result));
page.setPageSize(nums);
page.setPageNum(curr);
List<Course> list = scoreService.getCourseList(page, stu.getId(), result);
String jsonStr = StrUtil.RETURN_JONS_PRE_STR
+ page.getTotalItemsCount()
+ StrUtil.RETURN_JONS_MID_STR
+ JSON.toJSONString(list)
+ StrUtil.RETURN_JONS_END_STR;
System.out.println(jsonStr);
return jsonStr;
}
/**
* 学生选课
* @param session
* @param id
* @return
*/
@ResponseBody
@RequestMapping(value="/choiceCourse")
public String choiceCourse(HttpSession session,
@RequestParam(defaultValue="")Integer id) {
if (id != null) {
Student s = (Student) session.getAttribute(StrUtil.USER);
Score score = new Score();
score.setsId(s.getId());
score.setcId(id);
int res = scoreService.choiceCourse(score);
if (res > 0) return StrUtil.RESULT_TRUE;
else return StrUtil.RESULT_FALSE;
}
return "参数错误!";
}
/**
* 学生取消选课
* @param id
* @return
*/
@ResponseBody
@RequestMapping(value="/delete")
public String deleteCourse(@RequestParam(defaultValue="")Integer id, HttpSession session) {
Student stu = (Student) session.getAttribute(StrUtil.USER);
Score s = new Score();
s.setcId(id);
s.setsId(stu.getId());
if (id != null) {
int res = scoreService.deleteScore(s);
if (res > 0) return StrUtil.RESULT_TRUE;
else return StrUtil.RESULT_FALSE;
}
return "参数错误!";
}
/**
* 评分
* @param score
* @return
*/
@ResponseBody
@RequestMapping(value="/update")
public String updateScore(Score score) {
int res = scoreService.updateScore(score);
if (res > 0) return StrUtil.RESULT_TRUE;
else return StrUtil.RESULT_FALSE;
}
@ResponseBody
@RequestMapping(value="/updateList")
public String updateScoreList(String scoreListStr) {
List<Score> scoreList = JSON.parseArray(scoreListStr, Score.class);
System.out.println(scoreList);
int res = scoreService.updateScore(scoreList);
if (res > 0) return StrUtil.RESULT_TRUE;
else return StrUtil.RESULT_FALSE;
}
}
登录管理控制层:
@Controller
@RequestMapping(value="/login")
public class LoginController {
@Autowired
AuthService authService;
@Autowired
AdminService adminServiceImpl;
@Autowired
TeacherService teacherServiceImpl;
@Autowired
StudentService studentServiceImpl;
@RequestMapping(value="/loginPage")
public ModelAndView toLoginPage() {
return new ModelAndView("login");
}
@ResponseBody
@RequestMapping(value="/doLogin")
public String doLogin(@RequestParam(defaultValue="") String username,
@RequestParam(defaultValue="") String password,
@RequestParam(defaultValue="0") int userType,
@RequestParam(defaultValue="") String verifyCode, HttpSession session) {
//比较验证码
String sessionVerifyCode = (String) session.getAttribute(StrUtil.VERIFY_CODE);
if (sessionVerifyCode == null || !sessionVerifyCode.equals(verifyCode.toUpperCase()) ) {
return StrUtil.CODE_ERROR;
}
Login loginUser = null;
if (userType == 1) {
loginUser = (Login) adminServiceImpl;
} else if(userType == 2) {
loginUser = (Login) teacherServiceImpl;
} else if(userType == 3) {
loginUser = (Login) studentServiceImpl;
}
User user = loginUser.loginValidate(username, password.toUpperCase());//获得验证后user对象
if (user != null) {
//List<Auth> menuList = authService.getMenuList(user.getUserType());
List<Auth> urlList = authService.getUrlList(user.getUserType());
user.setUrlList(urlList);
//user.setMenuList(menuList);
session.setAttribute(StrUtil.USER, user);
return JSON.toJSONString(user);
}
return StrUtil.RESULT_FALSE;
}
@RequestMapping(value="/out")
public ModelAndView loginOut(HttpSession session) {
session.invalidate();//销毁sessions
//请求重定向到主页(login页)
return new ModelAndView("redirect:/");
}
@RequestMapping(value="/getVerifyCode")
public void getVerifyCode(HttpServletResponse response, HttpSession session) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
session.setAttribute("verifyCode", drawCodeImg(output));
try {
ServletOutputStream out = response.getOutputStream();
output.writeTo(out);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 绘出验证码
* @param output
* @return
*/
private String drawCodeImg(ByteArrayOutputStream output) {
String code = "";
for (int i = 0; i < 4; i++) {
code += randomChar();
}
int width = 70;
int height = 36;
BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Font font = new Font("Times New Roman", Font.PLAIN, 20);
Graphics2D graphics = bImage.createGraphics();
graphics.setFont(font);
graphics.setColor(new Color(66,2,82));
graphics.setBackground(new Color(226,226,240));
graphics.clearRect(0, 0, width, height);
FontRenderContext context = graphics.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(code, context);
double x = (width - bounds.getWidth()) / 2;
double y = (height - bounds.getHeight()) / 2;
double ascent = bounds.getY();
double baseY = y - ascent;
graphics.drawString(code, (int) x, (int) baseY);
graphics.dispose();
try {
ImageIO.write(bImage, "jpg", output);
} catch (IOException e) {
e.printStackTrace();
}
return code;
}
/**
* 返回一个随机字符
* @return
*/
private char randomChar() {
Random r = new Random();
String str = "ABCDEFGHJKLMNPRSTUVWXYZ0123456789";
return str.charAt(r.nextInt(str.length()));
}
}
源码获取:俺的博客首页 "资源" 里下载!