基于javaweb的调查问卷管理系统(java+springboot+vue+elementui+mysql)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)
项目介绍
- 本项目的在线问卷调查调查系统是基于SpringBoot开发的,采用了前后端分离模式来开发。
- 前端开发使用了Vue、Element UI,后端的开发则是使用了SpringBoot、MyBatis技术。
项目配置
- 下载项目压缩包,在IDEA或者Eclipse软件中打开,并修改application.yml文件中数据库的用户和密码 > * 在本地的MySQL数据库中导入项目的sql文件 > * 在编译器中运行该项目:此为SpringBoot框架,启动主类Main方法
- 在浏览器中输入localhost:8181后按回车键进入系统
用户管理控制器:
/**
*/
@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
Map
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)<&#61;0) {
ret.put(“msg”, “添加用户失败”);
return ret;
ret.put(“code”,0);
ret.put(“msg”,“添加用户成功”);
return ret;
/**
修改用户信息操作
&#64;param user
&#64;return
*/
&#64;PostMapping(“/editSaveUser”)
&#64;ApiOperation(“修改用户接口”)
&#64;PreAuthorize(“hasRole(‘管理员’)”)
&#64;ResponseBody
public Message editSaveUser(User 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(“修改用户信息失败”);
//添加用户
&#64;GetMapping(“/deleteUser”)
&#64;ApiOperation(“删除用户接口”)
&#64;ApiImplicitParams({
&#64;ApiImplicitParam(name &#61; “id”, value &#61; “如:88”,required &#61; true)
})
&#64;PreAuthorize(“hasRole(‘管理员’)”)
&#64;ResponseBody
public AjaxResult deleteUser(&#64;RequestParam(required &#61; true) Long id){
AjaxResult ajaxResult &#61; new AjaxResult();
try {
userService.deleteUser(id);
} catch (Exception e) {
e.printStackTrace();
return new AjaxResult(“删除失败”);
return ajaxResult;
&#64;PostMapping(value&#61;“/deleteBatchUser”)
&#64;ApiOperation(“批量删除用户接口”)
&#64;PreAuthorize(“hasRole(‘管理员’)”)
&#64;ResponseBody
public AjaxResult deleteBatchUser(String ids){
String[] idsArr &#61; ids.split(“,”);
List list &#61; new ArrayList();
for(int i&#61;0;i list.add(idsArr[i]); try{ userService.batchRemove(list); return new AjaxResult(); }catch(Exception e){ return new AjaxResult(“批量删除失败”); //查询所有角色 public List queryAllRole(){ return roleService.queryAll(); //添加用户的角色 &#64;PostMapping(“/addUserRole”) &#64;ApiOperation(“添加用户角色接口”) &#64;ApiImplicitParams({ &#64;ApiImplicitParam(name &#61; “paramMap”, value &#61; “如:{userId:1,[1,2,3,4]]}”) }) &#64;ResponseBody public AjaxResult addUserRole(&#64;RequestBody Map paramMap){ AjaxResult ajaxResult &#61; new AjaxResult(); String userId &#61; (String)paramMap.get(“userId”); List roleIds &#61; (List) paramMap.get(“roleIds”); try { //添加用户对应的角色 roleService.addUserRole(userId,roleIds); return ajaxResult; }catch (Exception e){ e.printStackTrace(); return new AjaxResult(“保存角色失败”); //添加用户 &#64;RequestMapping(“/regSaveUser”) &#64;ResponseBody public Long addTeacher(User user){ System.out.println(“保存用户…”&#43;user); userService.addUser(user); //保存工作流程操作 IdentityService is &#61; engine.getIdentityService(); // 添加用户组 org.activiti.engine.identity.User userInfo &#61; userService.saveUser(is, user.getUsername()); // 添加用户对应的组关系 Group stuGroup &#61; new GroupEntityImpl(); stuGroup.setId(“stuGroup”); Group tGroup &#61; new GroupEntityImpl(); tGroup.setId(“tGroup”); if(user.getType() &#61;&#61; 2) { //保存老师组 userService.saveRel(is, userInfo, tGroup); if(user.getType() &#61;&#61; 3) { //保存学生组 userService.saveRel(is, userInfo, stuGroup); Long userId &#61; user.getId(); return userId; /** 修改密码页面 &#64;return */ &#64;RequestMapping(value&#61;“/update_pwd”,method&#61;RequestMethod.GET) public String updatePwd(){ return “views/user/update_pwd”; /** 修改密码操作 &#64;param oldPwd &#64;param newPwd &#64;return */ &#64;ResponseBody &#64;PostMapping(“/update_pwd”) public Message updatePassword(&#64;RequestParam(name&#61;“oldPwd”,required&#61;true)String oldPwd, &#64;RequestParam(name&#61;“newPwd”,required&#61;true)String newPwd){ String username &#61; CommonUtils.getLoginUser().getUsername(); User userByUserName &#61; userService.findUserByUserName(username); if(userByUserName!&#61;null){ String password &#61; userByUserName.getPassword(); BCryptPasswordEncoder bCryptPasswordEncoder &#61; new BCryptPasswordEncoder(); boolean matches &#61; bCryptPasswordEncoder.matches(oldPwd, password); if(!matches){ return Message.error(“旧密码不正确”);//true userByUserName.setPassword(bCryptPasswordEncoder.encode(newPwd)); if(userService.editUserPassword(userByUserName)<&#61;0){ return Message.error(“密码修改失败”); return Message.success(); /** 清除缓存 &#64;param request &#64;param response &#64;return */ &#64;ResponseBody &#64;PostMapping(“/clear_cache”) public Message clearCache(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader(“Cache-Control”,“no-store”); response.setHeader(“Pragrma”,“no-cache”); response.setDateHeader(“Expires”,0); return Message.success(); 登录管理控制层&#xff1a; &#64;Controller public class LonginController { private final static Logger LOGGER &#61; LoggerFactory.getLogger(LonginController.class); public final static String LOGIN_TYPE &#61; “loginType”; &#64;Autowired &#64;Qualifier(“captchaProducer”) DefaultKaptcha captchaProducer; &#64;Autowired UserService userService; &#64;Autowired MenuService menuService; public enum LoginTypeEnum { PAGE,ADMIN; // &#64;RequestMapping(value &#61; “”) // public String welcome() { // return “redirect:admin”; // } &#64;RequestMapping(value &#61; {“admin”,“admin/index”}) public String adminIndex(RedirectAttributes attributes, ModelMap map) { Subject s &#61; SecurityUtils.getSubject(); attributes.addFlashAttribute(LOGIN_TYPE, LoginTypeEnum.ADMIN); if(s.isAuthenticated()) { return “redirect:index”; return “redirect:toLogin”; &#64;RequestMapping(value &#61; “toLogin”) public String adminToLogin(HttpSession session, &#64;ModelAttribute(LOGIN_TYPE) String loginType) { if(StringUtils.isBlank(loginType)) { LoginTypeEnum attribute &#61; (LoginTypeEnum) session.getAttribute(LOGIN_TYPE); loginType &#61; attribute &#61;&#61; null ? loginType : attribute.name(); if(LoginTypeEnum.ADMIN.name().equals(loginType)) { session.setAttribute(LOGIN_TYPE,LoginTypeEnum.ADMIN); return “admin/login”; }else { session.setAttribute(LOGIN_TYPE,LoginTypeEnum.PAGE); return “login”; &#64;RequestMapping(value &#61; “index”) public String index(HttpSession session, &#64;ModelAttribute(LOGIN_TYPE) String loginType) { if(StringUtils.isBlank(loginType)) { LoginTypeEnum attribute &#61; (LoginTypeEnum) session.getAttribute(LOGIN_TYPE); loginType &#61; attribute &#61;&#61; null ? loginType : attribute.name(); if(LoginTypeEnum.ADMIN.name().equals(loginType)) { AuthRealm.ShiroUser principal &#61; (AuthRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal(); session.setAttribute(“icon”,StringUtils.isBlank(principal.getIcon()) ? “/static/admin/img/face.jpg” : principal.getIcon()); return “admin/index”; }else { AuthRealm.ShiroUser principal &#61; (AuthRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal(); return “admin/index”; &#64;RequestMapping(“/getCaptcha”) public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException { //设置页面不缓存 response.setHeader(“Pragma”, “no-cache”); response.setHeader(“Cache-Control”, “no-cache”); response.setDateHeader(“Expires”, 0); String verifyCode &#61; captchaProducer.createText(); //将验证码放到HttpSession里面 request.getSession().setAttribute(Constants.VALIDATE_CODE, verifyCode); LOGGER.info(“本次生成的验证码为[” &#43; verifyCode &#43; “],已存放到HttpSession中”); //设置输出的内容的类型为JPEG图像 response.setContentType(“image/jpeg”); BufferedImage bufferedImage &#61; captchaProducer.createImage(verifyCode); //写给浏览器 ImageIO.write(bufferedImage, “JPEG”, response.getOutputStream()); &#64;PostMapping(“admin/login”) &#64;SysLog(“用户登录”) &#64;ResponseBody public ResponseEntity adminLogin(HttpServletRequest request) { String username &#61; request.getParameter(“username”); String password &#61; request.getParameter(“password”); String rememberMe &#61; request.getParameter(“rememberMe”); String code &#61; request.getParameter(“code”); String driver &#61; request.getParameter(“driver”); String errorMsg &#61; null; //判断登陆设备 if(StringUtils.isBlank(driver)){ //电脑登录 if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){ return ResponseEntity.failure(“用户名或者密码不能为空”); }else if(StringUtils.isBlank(code)){ return ResponseEntity.failure(“验证码不能为空”); HttpSession session &#61; request.getSession(); if(session &#61;&#61; null){ return ResponseEntity.failure(“session超时”); String trueCode &#61; (String)session.getAttribute(Constants.VALIDATE_CODE); if(StringUtils.isBlank(trueCode)){ return ResponseEntity.failure(“验证码超时”); if(StringUtils.isBlank(code) || !trueCode.toLowerCase().equals(code.toLowerCase())){ return ResponseEntity.failure(“验证码错误”); }else { Subject user &#61; SecurityUtils.getSubject(); UsernamePasswordToken token &#61; new UsernamePasswordToken(username,password,Boolean.valueOf(rememberMe)); try { user.login(token); }catch (IncorrectCredentialsException e) { errorMsg &#61; “用户名密码错误!”; }catch (UnknownAccountException e) { errorMsg &#61; “账户不存在!”; }catch (LockedAccountException e) { errorMsg &#61; “账户已被锁定!”; }catch (UserTypeAccountException e) { errorMsg &#61; “账户不是管理用户!”; if(StringUtils.isBlank(errorMsg)) { ResponseEntity responseEntity &#61; new ResponseEntity(); responseEntity.setSuccess(Boolean.TRUE); responseEntity.setAny(“url”,“index”); return responseEntity; }else { return ResponseEntity.failure(errorMsg); }else{ //小程序或APP登录 if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){ return ResponseEntity.failure(“用户名或者密码不能为空”); Subject user &#61; SecurityUtils.getSubject(); UsernamePasswordToken token &#61; new UsernamePasswordToken(username,password,Boolean.valueOf(rememberMe)); try { user.login(token); }catch (IncorrectCredentialsException e) { errorMsg &#61; “用户名或密码错误!”; }catch (UnknownAccountException e) { errorMsg &#61; “账户不存在!”; }catch (LockedAccountException e) { errorMsg &#61; “账户已被锁定!”; }catch (UserTypeAccountException e) { errorMsg &#61; “账户不是管理用户!”; if(StringUtils.isBlank(errorMsg)) { ResponseEntity responseEntity &#61; new ResponseEntity(); responseEntity.setSuccess(Boolean.TRUE); responseEntity.setAny(“url”,“index”); return responseEntity; }else { return ResponseEntity.failure(errorMsg); &#64;RequestMapping(“admin/main”) public String main(ModelMap map){ return “admin/main”; /*** 获得用户所拥有的菜单列表 &#64;return */ &#64;RequestMapping(“/admin/user/getUserMenu”) &#64;ResponseBody public List getUserMenu(){ String userId &#61; MySysUser.id(); List list &#61; menuService.getShowMenuByUser(userId); return list; &#64;RequestMapping(“systemLogout”) &#64;SysLog(“退出系统”) public String logOut(){ SecurityUtils.getSubject().logout(); return “redirect:home”;