Java 实战项目之毕业设计管理系统的实现流程
作者:qq_1334611189 时间:2021-12-26 00:10:10
一、项目简述
功能包括: 该系统不错分为学生,教师,管理员,教导主任四种角 色,包括学生管理,教师管理,学生选题,教师选题,主 任审核,管理员审核,开题报告,中期检查,论文提交, 文件管理等等非常不错。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
用户管理操作控制层:
/**
* 用户管理操作
*/
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
/**
* 用户添加页面
* @return
*/
@GetMapping("/add")
public String create() {
return "user/add";
}
/**
* 用户添加操作
* @param user
* @return
*/
@PostMapping("/add")
@ResponseBody
public Map<String, Object> add(@RequestBody User user) {
if(StringUtils.isEmpty(user.getUserName())){
return MapControl.getInstance().error("请填写用户名").getMap();
}
if(StringUtils.isEmpty(user.getName())){
return MapControl.getInstance().error("请填写名称").getMap();
}
if(StringUtils.isEmpty(user.getUserPwd())){
return MapControl.getInstance().error("请填写密码").getMap();
}
int result = userService.create(user);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
/**
* 根据id删除
* @param id
* @return
*/
@PostMapping("/delete/{id}")
@ResponseBody
public Map<String, Object> delete(@PathVariable("id") Integer id) {
int result = userService.delete(id);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//批量删除
@PostMapping("/delete")
@ResponseBody
public Map<String, Object> delete(String ids) {
int result = userService.delete(ids);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
/**
* 编辑用户信息操作
* @param user
* @return
*/
@PostMapping("/edit")
@ResponseBody
public Map<String, Object> edit(@RequestBody User user) {
if(StringUtils.isEmpty(user.getUserName())){
return MapControl.getInstance().error("请填写用户名").getMap();
}
if(StringUtils.isEmpty(user.getName())){
return MapControl.getInstance().error("请填写名称").getMap();
}
if(StringUtils.isEmpty(user.getUserPwd())){
return MapControl.getInstance().error("请填写密码").getMap();
}
int result = userService.update(user);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
/**
* 根据id查询,跳转修改页面
* @param id
* @param modelMap
* @return
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap modelMap) {
User user = userService.detail(id);
modelMap.addAttribute("user", user);
return "user/edit";
}
//查询所有
@PostMapping("/query")
@ResponseBody
public Map<String, Object> query(@RequestBody User user) {
List<User> list = userService.query(user);
Integer count = userService.count(user);
return MapControl.getInstance().success().page(list, count).getMap();
}
//跳转列表页面
@GetMapping("/list")
public String list() {
return "user/list";
}
}
跳转首页判断以及数据展示图表:
@Controller
public class IndexController {
@Autowired
UserService userService;
@Autowired
TeacherService teacherService;
@Autowired
StudentService studentService;
@Autowired
ClazzService clazzService;
@Autowired
SubjectService subjectService;
@Autowired
CourseService courseService;
@Autowired
SectionService sectionService;
@Autowired
ScoreService scoreService;
//跳转系统主页
@GetMapping("/index")
public String login() {
return "index";
}
//跳转用户基本信息页面
@GetMapping("/info")
public String info() {
return "info";
}
//跳转修改密码页面
@GetMapping("/pwd")
public String pwd() {
return "pwd";
}
//修改密码 根据旧密码来修改密码
@PostMapping("/pwd")
@ResponseBody
public Map<String,Object> pwd(String sourcePwd,String newPwd,String type,Integer id) {
//先判断类型
if("1".equals(type)) {
User user = userService.detail(id);
//比较原密码是否相同 注意:原密码也要加密后再进行比较,因为数据库中存储的是加密后的密码
if(user.getUserPwd().equals(MD5Utils.getMD5(sourcePwd))) {
User entity = new User();
entity.setId(id);
entity.setUserPwd(MD5Utils.getMD5(newPwd)); //主要要加密
int result = userService.update(entity);
if(result <= 0) {
return MapControl.getInstance().error().getMap();
} else {
return MapControl.getInstance().success().getMap();
}
} else {
return MapControl.getInstance().error("原密码错误").getMap();
}
}
if("2".equals(type)) {
Teacher teacher = teacherService.detail(id);
//比较原密码
if(teacher.getTeacherPwd().equals(MD5Utils.getMD5(sourcePwd))) {
Teacher entity = new Teacher();
entity.setId(id);
entity.setTeacherPwd(MD5Utils.getMD5(newPwd));
int result = teacherService.update(entity);
if(result <= 0) {
return MapControl.getInstance().error().getMap();
} else {
return MapControl.getInstance().success().getMap();
}
} else {
return MapControl.getInstance().error("原密码错误").getMap();
}
}
if("3".equals(type)) {
Student student = studentService.detail(id);
//比较原密码
if(student.getStuPwd().equals(MD5Utils.getMD5(sourcePwd))) {
Student entity = new Student();
entity.setId(id);
entity.setStuPwd(MD5Utils.getMD5(newPwd));
int result = studentService.update(entity);
if(result <= 0) {
return MapControl.getInstance().error().getMap();
} else {
return MapControl.getInstance().success().getMap();
}
} else {
return MapControl.getInstance().error("原密码错误").getMap();
}
}
return MapControl.getInstance().error().getMap();
}
//跳转系统主页(数据概览)
@GetMapping("/main")
public String main(ModelMap modelMap) {
//1.系统数据概览
List<Clazz> clazzes = clazzService.query(null);
List<Subject> subjects = subjectService.query(null);
List<Teacher> teachers = teacherService.query(null);
List<Course> courses = courseService.query(null);
List<Section> sections = sectionService.query(null);
List<Student> students = studentService.query(null);
modelMap.addAttribute("clazzCnt",clazzes.size());
modelMap.addAttribute("subjectCnt",subjects.size());
modelMap.addAttribute("teacherCnt",teachers.size());
modelMap.addAttribute("courseCnt",courses.size());
modelMap.addAttribute("studentCnt",students.size());
modelMap.addAttribute("sectionCnt",sections.size());
//2.班级学生数量
List<Map<String,Object>> mapList = new ArrayList<>();
for(Clazz clazz : clazzes) {
Map<String,Object> map = new HashMap<>();
map.put("name",clazz.getClazzName()); //设置班级名称
int cnt = 0;
//统计学生数量
for(Student student : students) {
if(student.getClazzId() == clazz.getId()) {
cnt++;
}
}
map.put("cnt",cnt); //设置学生数量
mapList.add(map);
}
modelMap.addAttribute("mapList",mapList);
//3.查询各科平均成绩(根据专业查询各科平均成绩)
List<HashMap> mapList2 = scoreService.queryAvgScoreBySection();
modelMap.addAttribute("mapList2",mapList2);
return "main";
}
}
公告管理控制器:
/**
* 公告管理控制器
*/
@Controller
@RequestMapping("/notice")
public class NoticeController {
@Autowired
private NoticeService noticeService;
//跳转添加页面
@GetMapping("/add")
public String add() {
return "notice/add";
}
/**
* 公告添加
* @param notice
* @return
*/
@PostMapping("/add")
@ResponseBody
public Map<String, Object> add(Notice notice, HttpServletRequest request) {
if(StringUtils.isEmpty(notice.getTitle())){
return MapControl.getInstance().error("请填写公告标题").getMap();
}
if(StringUtils.isEmpty(notice.getContent())){
return MapControl.getInstance().error("请填写公告内容").getMap();
}
User user = (User) request.getSession().getAttribute("user");
notice.setAuthor(user.getUserName());
notice.setAuth("1");
int result = noticeService.create(notice);
if (result <= 0) {
//新增失败
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//根据id删除
@PostMapping("/delete/{id}")
@ResponseBody
public Map<String, Object> delete(@PathVariable("id") Integer id) {
int result = noticeService.delete(id);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//批量删除
@PostMapping("/delete")
@ResponseBody
public Map<String, Object> delete(String ids) {
int result = noticeService.delete(ids);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
/**
* 修改公告操作
* @param notice
* @return
*/
@PostMapping("/edit")
@ResponseBody
public Map<String, Object> edit(@RequestBody Notice notice) {
if(StringUtils.isEmpty(notice.getTitle())){
return MapControl.getInstance().error("请填写公告标题").getMap();
}
if(StringUtils.isEmpty(notice.getContent())){
return MapControl.getInstance().error("请填写公告内容").getMap();
}
int result = noticeService.update(notice);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//根据id查询,跳转修改页面
@GetMapping("/edit/{id}")
public String edit(@PathVariable Integer id, ModelMap modelMap) {
//查询要修改的老师
Notice notice = noticeService.detail(id);
modelMap.addAttribute("notice", notice);
return "notice/edit";
}
//根据id查询,跳转添加页面
@GetMapping("/look/{id}")
public String look(@PathVariable Integer id, ModelMap modelMap) {
Notice notice = noticeService.detail(id);
modelMap.addAttribute("notice", notice);
return "notice/look";
}
//查询所有
@PostMapping("/query")
@ResponseBody
public Map<String, Object> query(@RequestBody Notice notice) {
List<Notice> list = noticeService.query(notice);
Integer count = noticeService.count(notice);
return MapControl.getInstance().success().put("data", list).put("count", count).getMap();
}
//跳转列表页面
@GetMapping("/list")
public String list() {
return "notice/list";
}
}
登陆用户判断业务控制层:
@Controller
public class LoginController {
@Autowired
private UserService userService;
@Autowired
private TeacherService teacherService;
@Autowired
private StudentService studentService;
//跳转登录页面
@GetMapping("/login")
public String login() {
return "login";
}
//登录操作
@PostMapping("/login")
@ResponseBody
public Map<String, Object> login(String userName, String password, String captcha, String type, HttpSession session) {
//判断用户名、密码、用户类型、验证码是否为空
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(captcha) || StringUtils.isEmpty(type)) {
return MapControl.getInstance().error("用户名或密码不能为空").getMap();
}
//获取系统生成的验证码
String _captcha = (String) session.getAttribute("captcha");
//先判断验证码是否正确
if (!(captcha.toLowerCase()).equals(_captcha.toLowerCase())) {
//验证码错误
return MapControl.getInstance().error("验证码错误").getMap();
}
//判断用户类型
if ("1".equals(type)) { //管理员验证登录
User user = userService.login(userName, MD5Utils.getMD5(password)); //对密码进行加密处理,因为数据库中存储的是加密后的密码
if (user != null) {
session.setAttribute("user", user);
session.setAttribute("type", 1);
return MapControl.getInstance().success().add("data", user).getMap();
} else {
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
if ("2".equals(type)) { //老师验证登录
Teacher teacher = teacherService.login(userName, MD5Utils.getMD5(password));
if (teacher != null) {
session.setAttribute("user", teacher);
session.setAttribute("type", "2");
return MapControl.getInstance().success().add("data", teacher).getMap();
} else {
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
if ("3".equals(type)) { //学生验证登录
Student student = studentService.login(userName, MD5Utils.getMD5(password));
if (student != null) {
session.setAttribute("user", student);
session.setAttribute("type", "3");
return MapControl.getInstance().success().add("data", student).getMap();
} else {
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
return MapControl.getInstance().getMap();
}
}
来源:https://blog.csdn.net/m0_59687645/article/details/121435680
标签:Java,毕业设计,管理系统,实战
0
投稿
猜你喜欢
Spring Security 实现短信验证码登录功能
2022-11-02 19:39:30
详解Spring Bean 之间的特殊关系
2022-10-25 21:12:17
解决android.support.v4.content.FileProvide找不到的问题
2022-09-10 05:42:57
Spring Boot日志技术logback原理及配置解析
2022-09-14 10:51:57
Kotlin基础教程之伴生对象,getter,setter,内部,局部,匿名类,可变参数
2021-08-05 03:56:02
Spring Boot2.3 新特性分层JAR的使用
2021-08-03 12:55:50
Android之PreferenceActivity应用详解
2023-03-28 14:26:37
springboot实现文件上传步骤解析
2023-01-31 22:15:42
C#实现数字华容道游戏
2023-10-26 10:01:07
java ThreadGroup的作用及方法详解
2022-02-03 16:49:01
Java中的多态用法实例分析
2021-07-11 18:36:35
Android实现关机重启的方法分享
2022-11-13 21:32:33
浅谈byte和长度为8的boolean数组互相转换
2023-11-07 00:34:37
Android通过实现GridView的横向滚动实现仿京东秒杀效果
2023-06-08 22:53:46
Java多线程编程综合案例详解
2023-12-09 18:13:25
Springboot+ElementUi实现评论、回复、点赞功能
2022-06-16 04:34:00
C#识别出图片里的数字和字母
2023-04-12 08:21:41
解析Java线程同步锁的选择方法
2023-02-08 11:02:32
C#实现生成所有不重复的组合功能示例
2023-04-18 15:49:43
C#判断上传文件是否是图片以防止木马上传的方法
2023-10-02 13:13:50