Java项目:教室预订管理系统(java+SpringBoot+Maven+Vue+mysql)

news/2024/7/10 0:34:38 标签: java, mysql, maven, vue, spring boot

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

一、项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。

项目技术:

Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
 

 

 

 

 

用户管理控制器:

/**
 * 用户管理控制器
 */
@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<Role> 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<String,Object> addUser(User user){
        Map<String, Object> 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<idsArr.length;i++){
            list.add(idsArr[i]);
        }
        try{
            userService.batchRemove(list);
            return new AjaxResult();
        }catch(Exception e){
           return new AjaxResult("批量删除失败");
        }
    }

    //查询所有角色
    public List<Role> 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 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<Permission> 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("保存权限失败");
        }

    }

}

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


http://www.niftyadmin.cn/n/1554262.html

相关文章

mysql c api用的多吗_mysql C API 多语句插入数据有关问题

mysql C API 多语句插入数据问题打开连接时用mysql_real_connect()&#xff0c;传递参数CLIENT_MULTI_STATEMENTS以支持多语句查询每执行mysql_query()来插入数据后&#xff0c;调用以下函数来清空返回结果集&#xff0c;以避免2014错误void clear_result(MYSQL* conn){if(!con…

Java项目:仓库管理系统(java+SSM+Maven+Bootstrap+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 基于SSM框架的仓库管理系统 功能: * 系统操作权限管理。系统提供基本的登入登出功能&#xff0c;同时系统包含两个角色&#xff1a;系统超级管理员和普通管理员&#xff0c;超级管理员具有最高的操作权限&…

面试官 谈谈你对mysql索引的认识_【原创】面试官:谈谈你对mysql联合索引的认识?...

引言本文预计分为两个部分:(1)联合索引部分的基础知识在这个部分&#xff0c;我们温习一下联合索引的基础(2)联合索引部分的实战题在这个部分&#xff0c;列举几个我认为算是实战中的代表题&#xff0c;挑出来说说。正文基础讲联合索引&#xff0c;一定要扯最左匹配!放心&#…

Java项目:在线电子书小说阅读系统(java+Layui+Springboot+Maven+mysql+HTML+FTP)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目介绍 环境配置&#xff1a; Jdk1.8 Tomcat8.5 mysql Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09; 项目技术&#xff1a; LayuiSpringboot SpringMVC HTML F…

mysql临时表删除_MySQL如何创建和删除临时表

1.介绍&#xff1a;MySQL临时表&#xff0c;属于session级别&#xff0c;当session退出时&#xff0c;临时表被删除。临时表允许与其他表同名&#xff0c;并单独维护在thd的结构体中&#xff1b;因此&#xff0c;不同的session可以创建同名的临时表&#xff0c;并且只操作自己拥…

Java项目:OA办公管理系统(java+Layui+SSM+Maven+mysql+JSP+html)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 mysql Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09; 项目技术&#xff1a; JSP Spring SpringMVC MyBatis ht…

Java项目:精美风在线音乐系统(java+JDBC+C3P0+servlet+mysql+JSP)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 1.运行环境 环境配置&#xff1a; Jdk1.8 Tomcat8.5 mysql Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09; 项目技术&#xff1a; JSP C3P0 Servlert html css JavaS…

mysql 写.sh_mysqlsh(mysql shell)学习

简介mysqlsh是个msyql的命令行工具,好像很智能,官方推荐在5.7和8版本中使用.我对这个有些不了解,以为它就是个简单的sql命令执行工具,后来我才发现,事情并没有想象中简单.现在我简单理解为它是交互式命令行工具,可以在其中运行python,js代码来操作mysql,省去了繁琐的sql操作.官…