本文主要是介绍基于javaweb+mysql的校园一卡通系统(java+JSP+Servlet+html+css+JavaScript+JQuery+Ajax+mysql),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、项目简述
功能:卡管理,卡消费,卡充值,图书借阅,消费,记录,注销等等功能。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP + Servlet + html+ css + JavaScript + JQuery + Ajax 等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
}/*** 角色修改表单提交处理* @param request* @param role* @return*/@RequestMapping(value="/edit",method=RequestMethod.POST)@ResponseBodypublic Result<Boolean> edit(Role role){//用统一验证实体方法验证是否合法CodeMsg validate = ValidateEntityUtil.validate(role);if(validate.getCode() != CodeMsg.SUCCESS.getCode()){return Result.error(validate);}Role existRole = roleService.find(role.getId());if(existRole == null){
return "redirect:update_userinfo";}/*** 修改密码页面* @return*/@RequestMapping(value="/update_pwd",method=RequestMethod.GET)public String updatePwd(){return "admin/system/update_pwd";}/*** 修改密码表单提交* @param oldPwd* @param newPwd* @return*/
model.addAttribute("userTotal", userService.total());model.addAttribute("operatorLogTotal", operaterLogService.total());model.addAttribute("databaseBackupTotal", databaseBakService.total());model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);return "admin/system/index";}/*** 注销登录* @return*/@RequestMapping(value="/logout")public String logout(){Integer loginType = (Integer) SessionUtil.get("loginType");if(loginType == LoginType.ADMINISTRATOR.getCode()){User loginedUser = SessionUtil.getLoginedUser();if(loginedUser != null){
modelMap.addAttribute("user", user);return "user/edit";}//查询所有@PostMapping("/query")@ResponseBodypublic 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 LoginController {@Autowiredprivate UserService userService;@Autowired
@PostMapping("/login")@ResponseBodypublic 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();
request.getSession().setAttribute("loginType",type);//销毁session中的验证码request.getSession().setAttribute("admin_login", null);//将登陆记录写入日志库operaterLogService.add("用户【"+username+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!");log.info("员工成功登录,user = " + byJobNumber);}return Result.success(true);}/*** 登录成功后的系统主页* @param model* @return*/@RequestMapping(value="/index")public String index(Model model){model.addAttribute("operatorLogs", operaterLogService.findLastestLog(10));model.addAttribute("userTotal", userService.total());model.addAttribute("operatorLogTotal", operaterLogService.total());model.addAttribute("databaseBackupTotal", databaseBakService.total());model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);return "admin/system/index";
@Autowiredprivate MenuService menuService;@Autowiredprivate OperaterLogService operaterLogService;@Autowiredprivate RoleService roleService;/*** 分页搜索角色列表* @param model* @param role* @param pageBean* @return*/@RequestMapping(value="/list")public String list(Model model,Role role,PageBean<Role> pageBean){model.addAttribute("title", "角色列表");model.addAttribute("name", role.getName());model.addAttribute("pageBean", roleService.findByName(role, pageBean));return "admin/role/list";}
orderAuth.setOrderSn(orderSn);orderAuth.setPhone(phone);orderAuthService.save(orderAuth);AppConfig.ORDER_AUTH = 1;return Result.success(true);}/*** 删除操作日志,可删除多个* @param ids* @return*/@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)@ResponseBodypublic Result<Boolean> delete(String ids){
if(newPwd.length()<4 || newPwd.length()>32){return Result.error(CodeMsg.ADMIN_USER_PWD_LENGTH_ERROR);}loginedUser.setPassword(newPwd);//保存数据库userService.save(loginedUser);//更新sessionSessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);}else{Staff loginedStaff = SessionUtil.getLoginedStaff();Staff staff = staffService.find(loginedStaff.getId());if(!staff.getPassword().equals(oldPwd)){return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);}if(StringUtils.isEmpty(newPwd)){return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);}staff.setPassword(newPwd);CodeMsg codeMsg = ValidateEntityUtil.validate(staff);if (codeMsg.getCode() != CodeMsg.SUCCESS.getCode()){return Result.error(codeMsg);}
* 清空整个日志* @return*/@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)@ResponseBodypublic Result<Boolean> deleteAll(){operaterLogService.deleteAll();return Result.success(true);}
}
用户管理操作控制层:
/*** 用户管理操作*/
@Controller
@RequestMapping("/user")
/*** 角色添加表单提交处理* @param role* @return*/@RequestMapping(value="/add",method=RequestMethod.POST)@ResponseBodypublic Result<Boolean> add(Role role){//用统一验证实体方法验证是否合法CodeMsg validate = ValidateEntityUtil.validate(role);if(validate.getCode() != CodeMsg.SUCCESS.getCode()){return Result.error(validate);}if(roleService.save(role) == null){return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);}
这篇关于基于javaweb+mysql的校园一卡通系统(java+JSP+Servlet+html+css+JavaScript+JQuery+Ajax+mysql)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!