基于javaweb的学校在线报考系统(java+jsp+javascript+servlet+mysql) | 您所在的位置:网站首页 › 报考java › 基于javaweb的学校在线报考系统(java+jsp+javascript+servlet+mysql) |
基于javaweb的学校在线报考系统(java+jsp+javascript+servlet+mysql) 运行环境 Java≥8、MySQL≥5.7、Tomcat≥8 开发工具 eclipse/idea/myeclipse/sts等均可配置运行 适用 课程设计,大作业,毕业设计,项目练习,学习演示等 功能说明 基于javaweb+mysql的学校在线报考系统(java+JSP+JavaScript+servlet+Mysql) 项目介绍 本项目分为管理员、教务人员、招生人员、学生等角色; 管理员角色主要功能包括: 系统状态、阶段定义、管理员维护、数据库管理、查看报名信息、我的登录历史、修改密码、退出系统; 教务人员主要功能包括: 系统状态、查看报名信息、准考证号分配、考场分配、录入成绩、我的登录历史、修改密码、退出系统; 招生人员主要功能包括: 系统状态、阶段设置、招考信息设置、查看报名信息、现场确认、学生密码清零、我的登录历史、修改密码、退出系统; 学生角色主要功能包括: 报考须知、我的报名信息、上传照片、报名表打印、准考证打印、成绩与录取查询、我的登录历史、修改密码、退出系统等; 环境需要 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项目:否; 技术栈 后端:Servlet 2. 前端:JSP+JavaScript+CSS使用说明 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中WebRoot/META-INF/context.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目,学生角色使用http://localhost:8080/bkxt/index.jsp进行登录 学生账号/密码:zjfhit/123456 管理员登录:http://localhost:8080/bkxt/manage.jsp 管理员账号/密码:manager/123456 教务人员账号/密码:jiaowu/123456 招生人员账号/密码:zhaoban/123456角色控制层: @Controller public class RoleController { @Autowired private IRoleService roleService; @Autowired private IPermissionService permissionService; @PreAuthorize(“hasRole(‘管理员’)”) @ResponseBody @RequestMapping(“/role/doAdd”) public String doAdd(Role role){ //角色添加 return “ok”; //添加角色 @RequestMapping(“/role/addRole”) @PreAuthorize(“hasRole(‘管理员’)”) @ResponseBody public AjaxResult addRole(Role role){ System.out.println(“保存角色…”+role); try { roleService.saveRole(role); return new AjaxResult(); } catch (Exception e) { e.printStackTrace(); return new AjaxResult(“操作失败”); @PreAuthorize(“hasRole(‘管理员’)”) @RequestMapping(“/role/index”) public String index(Model model){ List permisisons = permissionService.findAllPermisisons(); model.addAttribute(“permissions”,permisisons); //返回角色 return “views/role/role_list”; @RequestMapping(“/role/listpage”) @ResponseBody public PageList listpage(RoleQuery roleQuery){ System.out.println(“传递参数:”+roleQuery); return roleService.listpage(roleQuery); //修改用户editSaveUser @RequestMapping(“/role/editSaveRole”) @ResponseBody public AjaxResult editSaveRole(Role role){ System.out.println(“修改角色…”+role); try { roleService.editSaveRole(role); return new AjaxResult(); } catch (Exception e) { e.printStackTrace(); return new AjaxResult(“修改失败”); //添加角色 @RequestMapping(“/role/deleteRole”) @ResponseBody public AjaxResult deleteRole(Long id){ System.out.println(“删除角色…”+id); AjaxResult ajaxResult = new AjaxResult(); try { roleService.deleteRole(id); } catch (Exception e) { e.printStackTrace(); return new AjaxResult(“删除失败”); return ajaxResult; //添加角色权限 addRolePermission @RequestMapping(“/role/addRolePermission”) @ResponseBody public AjaxResult addRolePermission(@RequestBody Map paramMap){ AjaxResult ajaxResult = new AjaxResult(); String roleId = (String)paramMap.get(“roleId”); List permissionIds = (List) paramMap.get(“permissionIds”); try { //添加角色对应的权限 roleService.addRolePermission(roleId,permissionIds); return ajaxResult; }catch (Exception e){ e.printStackTrace(); return new AjaxResult(“保存权限失败”); 用户管理控制器: /** 用户管理控制器*/ @RequestMapping(“/user/”) @Controller public class UserController { @Autowired private IUserService userService; @Autowired private IRoleService roleService; @Resource private ProcessEngineConfiguration configuration; @Resource private ProcessEngine engine; @GetMapping(“/index”) @ApiOperation(“跳转用户页接口”) @PreAuthorize(“hasRole(‘管理员’)”) public String index(String menuid,Model model){ List roles = queryAllRole(); model.addAttribute(“roles”,roles); model.addAttribute(“menuid”,menuid); //用户首页 return “views/user/user_list”; @GetMapping(“/listpage”) @ApiOperation(“查询用户分页数据接口”) @ApiImplicitParams({ @ApiImplicitParam(name = “UserQuery”, value = “用户查询对象”, defaultValue = “userQuery对象”) }) @ResponseBody @PreAuthorize(“hasRole(‘管理员’)”) public PageList listpage(UserQuery userQuery){ return userService.listpage(userQuery); //添加用户 @PostMapping(“/addUser”) @ApiOperation(“添加用户接口”) @ResponseBody public Map addUser(User user){ Map ret = new HashMap(); ret.put(“code”,-1); if(StringUtils.isEmpty(user.getUsername())){ ret.put(“msg”,“请填写用户名”); return ret; if(StringUtils.isEmpty(user.getPassword())){ ret.put(“msg”,“请填写密码”); return ret; if(StringUtils.isEmpty(user.getEmail())){ ret.put(“msg”,“请填写邮箱”); return ret; if(StringUtils.isEmpty(user.getTel())){ ret.put(“msg”,“请填写手机号”); return ret; if(StringUtils.isEmpty(user.getHeadImg())){ ret.put(“msg”,“请上传头像”); return ret; if(userService.addUser(user) if(StringUtils.isEmpty(user.getUsername())){ return Message.error(“请填写用户名”); if(StringUtils.isEmpty(user.getEmail())){ return Message.error(“请填写邮箱”); if(StringUtils.isEmpty(user.getTel())){ return Message.error(“请填写手机号”); try { userService.editSaveUser(user); return Message.success(); } catch (Exception e) { e.printStackTrace(); return Message.error(“修改用户信息失败”); //添加用户 @GetMapping(“/deleteUser”) @ApiOperation(“删除用户接口”) @ApiImplicitParams({ @ApiImplicitParam(name = “id”, value = “如:88”,required = true) }) @PreAuthorize(“hasRole(‘管理员’)”) @ResponseBody public AjaxResult deleteUser(@RequestParam(required = true) Long id){ AjaxResult ajaxResult = new AjaxResult(); try { userService.deleteUser(id); } catch (Exception e) { e.printStackTrace(); return new AjaxResult(“删除失败”); return ajaxResult; @PostMapping(value=“/deleteBatchUser”) @ApiOperation(“批量删除用户接口”) @PreAuthorize(“hasRole(‘管理员’)”) @ResponseBody public AjaxResult deleteBatchUser(String ids){ String[] idsArr = ids.split(“,”); List list = new ArrayList(); for(int i=0;i userService.batchRemove(list); return new AjaxResult(); }catch(Exception e){ return new AjaxResult(“批量删除失败”); //查询所有角色 public List queryAllRole(){ return roleService.queryAll(); //添加用户的角色 @PostMapping(“/addUserRole”) @ApiOperation(“添加用户角色接口”) @ApiImplicitParams({ @ApiImplicitParam(name = “paramMap”, value = “如:{userId:1,[1,2,3,4]]}”) }) @ResponseBody public AjaxResult addUserRole(@RequestBody Map paramMap){ AjaxResult ajaxResult = new AjaxResult(); String userId = (String)paramMap.get(“userId”); List roleIds = (List) paramMap.get(“roleIds”); try { //添加用户对应的角色 roleService.addUserRole(userId,roleIds); return ajaxResult; }catch (Exception e){ e.printStackTrace(); return new AjaxResult(“保存角色失败”); //添加用户 @RequestMapping(“/regSaveUser”) @ResponseBody public Long addTeacher(User user){ System.out.println(“保存用户…”+user); userService.addUser(user); //保存工作流程操作 IdentityService is = engine.getIdentityService(); // 添加用户组 org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername()); // 添加用户对应的组关系 Group stuGroup = new GroupEntityImpl(); stuGroup.setId(“stuGroup”); Group tGroup = new GroupEntityImpl(); tGroup.setId(“tGroup”); if(user.getType() == 2) { //保存老师组 userService.saveRel(is, userInfo, tGroup); if(user.getType() == 3) { //保存学生组 userService.saveRel(is, userInfo, stuGroup); Long userId = user.getId(); return userId; /** 修改密码页面 @return */ @RequestMapping(value=“/update_pwd”,method=RequestMethod.GET) public String updatePwd(){ return “views/user/update_pwd”; /** 修改密码操作 @param oldPwd @param newPwd @return */ @ResponseBody @PostMapping(“/update_pwd”) public Message updatePassword(@RequestParam(name=“oldPwd”,required=true)String oldPwd, @RequestParam(name=“newPwd”,required=true)String newPwd){ String username = CommonUtils.getLoginUser().getUsername(); User userByUserName = userService.findUserByUserName(username); if(userByUserName!=null){ String password = userByUserName.getPassword(); BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); boolean matches = bCryptPasswordEncoder.matches(oldPwd, password); if(!matches){ return Message.error(“旧密码不正确”);//true userByUserName.setPassword(bCryptPasswordEncoder.encode(newPwd)); if(userService.editUserPassword(userByUserName) response.setHeader(“Cache-Control”,“no-store”); response.setHeader(“Pragrma”,“no-cache”); response.setDateHeader(“Expires”,0); return Message.success(); 公用的上传类: /** 公用的上传类*/ @RequestMapping(“/upload”) @Controller public class UploadController { @Value(“${lyy.upload.photo.sufix}”) private String uploadPhotoSufix; @Value(“${lyy.upload.photo.maxsize}”) private long uploadPhotoMaxSize; @Value(“${lyy.upload.path}”) private String uploadPhotoPath;//文件保存位置 private Logger log = LoggerFactory.getLogger(UploadController.class); /** 图片统一上传类 @param photo @return */ @RequestMapping(value=“/upload_photo”,method=RequestMethod.POST) @ResponseBody public Map uploadPhoto(@RequestParam(name=“photo”,required=true)MultipartFile photo){ Map ret = new HashMap(); ret.put(“code”,-1); //判断文件类型是否是图片 String originalFilename = photo.getOriginalFilename(); //获取文件后缀 String suffix = originalFilename.substring(originalFilename.lastIndexOf(“.”),originalFilename.length()); if(!uploadPhotoSufix.contains(suffix.toLowerCase())){ ret.put(“msg”,“请上传正确图片格式”); return ret; if(photo.getSize()/1024 > uploadPhotoMaxSize){ ret.put(“msg”,“图片大小不能超过” + (uploadPhotoMaxSize/1024) + “M”); return ret; //准备保存文件 File filePath = new File(uploadPhotoPath); if(!filePath.exists()){ //若不存在文件夹,则创建一个文件夹 filePath.mkdir(); String uuidString = UUID.randomUUID().toString(); String newFileName= uuidString + suffix; try { photo.transferTo(new File(uploadPhotoPath+“/”+newFileName)); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); ret.put(“code”,0); ret.put(“filename”,newFileName); return ret; |
CopyRight 2018-2019 实验室设备网 版权所有 |