Java项目:调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)

源码获取:博客首页 "资源" 里下载!

项目介绍

> * 本项目的在线问卷调查调查系统是基于SpringBoot开发的,采用了前后端分离模式来开发。

> * 前端开发使用了Vue、Element UI,后端的开发则是使用了SpringBoot、MyBatis技术。

项目配置

> * 下载项目压缩包,在IDEA或者Eclipse软件中打开,并修改**application.yml**文件中数据库的用户和密码
> * 在本地的MySQL数据库中导入项目的**sql文件**
> * 在编译器中运行该项目:此为SpringBoot框架,启动主类Main方法

> * 在浏览器中输入**localhost:8181**后按回车键进入系统

Java项目:调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)_第1张图片

 Java项目:调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)_第2张图片

 Java项目:调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)_第3张图片

 Java项目:调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)_第4张图片

 Java项目:调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)_第5张图片

 Java项目:调查问卷管理系统(java+SpringBoot+Vue+ElementUI+Maven+mysql)_第6张图片

用户管理控制器:

/**
 * 用户管理控制器
 */
@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)<=0) {
            ret.put("msg", "添加用户失败");
            return ret;
        }
        ret.put("code",0);
        ret.put("msg","添加用户成功");
        return ret;
    }

    /**
     * 修改用户信息操作
     * @param user
     * @return
     */
    @PostMapping("/editSaveUser")
    @ApiOperation("修改用户接口")
    @PreAuthorize("hasRole('管理员')")
    @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("修改用户信息失败");
        }

    }

    //添加用户
    @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 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)<=0){
                return Message.error("密码修改失败");
            }
        }
        return Message.success();
    }

    /**
     * 清除缓存
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @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();
    }
}

登录管理控制层:

@Controller
public class LonginController {

    private final static Logger LOGGER = LoggerFactory.getLogger(LonginController.class);

    public final static String LOGIN_TYPE = "loginType";

    @Autowired
    @Qualifier("captchaProducer")
    DefaultKaptcha captchaProducer;

    @Autowired
    UserService userService;

    @Autowired
    MenuService menuService;

    public enum LoginTypeEnum {
        PAGE,ADMIN;
    }

//    @RequestMapping(value = "")
//    public String welcome() {
//        return "redirect:admin";
//    }

    @RequestMapping(value = {"admin","admin/index"})
    public String adminIndex(RedirectAttributes attributes, ModelMap map) {
        Subject s = SecurityUtils.getSubject();
        attributes.addFlashAttribute(LOGIN_TYPE, LoginTypeEnum.ADMIN);
        if(s.isAuthenticated()) {
            return "redirect:index";
        }
        return "redirect:toLogin";
    }

    @RequestMapping(value = "toLogin")
    public String adminToLogin(HttpSession session, @ModelAttribute(LOGIN_TYPE) String loginType) {
        if(StringUtils.isBlank(loginType)) {
            LoginTypeEnum attribute = (LoginTypeEnum) session.getAttribute(LOGIN_TYPE);
            loginType = attribute == 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";
        }
    }

    @RequestMapping(value = "index")
    public String index(HttpSession session, @ModelAttribute(LOGIN_TYPE) String loginType) {
        if(StringUtils.isBlank(loginType)) {
            LoginTypeEnum attribute = (LoginTypeEnum) session.getAttribute(LOGIN_TYPE);
            loginType = attribute == null ? loginType : attribute.name();
        }
        if(LoginTypeEnum.ADMIN.name().equals(loginType)) {
            AuthRealm.ShiroUser principal = (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 = (AuthRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();

            return "admin/index";
        }

    }

    @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 = captchaProducer.createText();
        //将验证码放到HttpSession里面
        request.getSession().setAttribute(Constants.VALIDATE_CODE, verifyCode);
        LOGGER.info("本次生成的验证码为[" + verifyCode + "],已存放到HttpSession中");
        //设置输出的内容的类型为JPEG图像
        response.setContentType("image/jpeg");
        BufferedImage bufferedImage = captchaProducer.createImage(verifyCode);
        //写给浏览器
        ImageIO.write(bufferedImage, "JPEG", response.getOutputStream());
    }

    @PostMapping("admin/login")
    @SysLog("用户登录")
    @ResponseBody
    public ResponseEntity adminLogin(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String rememberMe = request.getParameter("rememberMe");
        String code = request.getParameter("code");
        String driver = request.getParameter("driver");
        String errorMsg = 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 = request.getSession();
            if(session == null){
                return ResponseEntity.failure("session超时");
            }
            String trueCode = (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 = SecurityUtils.getSubject();
                UsernamePasswordToken token = new UsernamePasswordToken(username,password,Boolean.valueOf(rememberMe));
                try {
                    user.login(token);
                }catch (IncorrectCredentialsException e) {
                    errorMsg = "用户名密码错误!";
                }catch (UnknownAccountException e) {
                    errorMsg = "账户不存在!";
                }catch (LockedAccountException e) {
                    errorMsg = "账户已被锁定!";
                }catch (UserTypeAccountException e) {
                    errorMsg = "账户不是管理用户!";
                }
                if(StringUtils.isBlank(errorMsg)) {
                    ResponseEntity responseEntity = 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 = SecurityUtils.getSubject();
            UsernamePasswordToken token = new UsernamePasswordToken(username,password,Boolean.valueOf(rememberMe));
            try {
                user.login(token);
            }catch (IncorrectCredentialsException e) {
                errorMsg = "用户名或密码错误!";
            }catch (UnknownAccountException e) {
                errorMsg = "账户不存在!";
            }catch (LockedAccountException e) {
                errorMsg = "账户已被锁定!";
            }catch (UserTypeAccountException e) {
                errorMsg = "账户不是管理用户!";
            }
            if(StringUtils.isBlank(errorMsg)) {
                ResponseEntity responseEntity = new ResponseEntity();
                responseEntity.setSuccess(Boolean.TRUE);
                responseEntity.setAny("url","index");
                return responseEntity;
            }else {
                return ResponseEntity.failure(errorMsg);
            }
        }





    }

    @RequestMapping("admin/main")
    public String main(ModelMap map){
        return "admin/main";
    }

    /***
     * 获得用户所拥有的菜单列表
     * @return
     */
    @RequestMapping("/admin/user/getUserMenu")
    @ResponseBody
    public List getUserMenu(){
        String userId = MySysUser.id();
        List list = menuService.getShowMenuByUser(userId);
        return list;
    }

    @RequestMapping("systemLogout")
    @SysLog("退出系统")
    public String logOut(){
        SecurityUtils.getSubject().logout();
        return "redirect:home";
    }

}

源码获取:博客首页 "资源" 里下载! 

你可能感兴趣的:(Java毕业设计项目实战篇,java,mysql,spring,boot,vue.js,elementui)