Java 实战项目锤炼之校园宿舍管理系统的实现流程
更新时间:2021年11月12日 08:51:39 作者:qq_1334611189
读万卷书不如行万里路,只学书上的理论是远远不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用java+jsp+javaweb+mysql+ajax实现一个校园宿舍管理系统,大家可以在过程中查缺补漏,提升水平
一、项目简述
功能:宿舍管理员,最高管理员,学生三个身份,包括学 生管理,宿舍管理员管理,考勤管理,宿舍楼管理,缺勤 记录管理,个人信息修改等等功能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术: JSP + Entity+ Servlert + html+ css + JavaScript + JQuery + Ajax 等等。




用户登录操作代码:
用户登录操作:
@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();
}
}
用户登出操作代码:
用户登出操作:
@Controller
public class LogoutController {
//退出操作
@RequestMapping("/logout")
public String logout(HttpSession session) {
//让session失效
session.invalidate();
//重定向到登录页
return "redirect:login";
}
}
以上就是Java 实战项目锤炼之校园宿舍管理系统的实现流程的详细内容,更多关于Java 校园宿舍管理系统的资料请关注脚本之家其它相关文章!
相关文章
SpringCloud Tencent 全套解决方案源码分析
Spring Cloud Tencent实现Spring Cloud标准微服务SPI,开发者可以基于Spring Cloud Tencent开发Spring Cloud微服务架构应用,Spring Cloud Tencent 的核心依托腾讯开源的一站式服务发现与治理平台 Polarismesh,实现各种分布式微服务场景,感兴趣的朋友一起看看吧2022-07-07
Java格式化输出详细讲解(printf、print、println、format等)
Java的格式化输出等同于String.Format,与C有很大的相似,下面这篇文章主要给大家介绍了关于Java格式化输出(printf、print、println、format等)的相关资料,文中通过图文介绍的非常详细,需要的朋友可以参考下2023-03-03


最新评论