当前位置:首页 » 《随便一记》 » 正文

Java项目:学生信息管理系统(java+SSM+jsp+mysql+maven)_qq_1334611189的博客

5 人参与  2022年06月02日 14:50  分类 : 《随便一记》  评论

点击全文阅读


一、项目简述

功能包括: 用户的登录注册,学生信息管理,教师信息管理,班级信 息管理,采用mvcx项目架构,覆盖增删改查,包括学生, 教币班级的信息导出上传导入等等功能。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + 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();
    }
}

教师管理接口控制器:

@RequestMapping("/teacher")
@Controller
@Api(tags = "教师管理接口")
public class TeacherController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IClassesService classesService;
    @Resource
    private ProcessEngine engine;
    @Autowired
    private IOperaterLogService operaterLogService;


    //老师列表
    @RequestMapping("/index")
    public String index(Model model){
        //用户首页
        model.addAttribute("classes",classesService.queryAll());
        return "views/teacher/teacher_list";
    }

    @RequestMapping("/listpage")
    @ResponseBody
    public PageList listpage(UserQuery userQuery){
        userQuery.setType(2L);//2表示老师
        return  userService.listpage(userQuery);
    }

    /**
     * 添加教师操作
     * @param user
     * @return
     */
    @PostMapping("/addTeacher")
    @ApiOperation("添加教师接口")
    @ResponseBody
    @PreAuthorize("hasRole('管理员')")
    public Message addTeacher(User user){
        if(StringUtils.isEmpty(user.getUsername())){
            return Message.error("请填写用户名");
        }
        if(StringUtils.isEmpty(user.getPassword())){
            return Message.error("请填写密码");
        }
        if(StringUtils.isEmpty(user.getEmail())){
            return Message.error("请填写邮箱");
        }
        if(StringUtils.isEmpty(user.getTel())){
            return Message.error("请填写手机号");
        }
        User userByUserName = userService.findUserByUserName(user.getUsername());
        if(userByUserName!=null){
            return Message.error("用户名已存在");
        }
        user.setType(2);
        if(userService.addUser(user)<=0){
            return Message.error("教师添加失败");
        }
        //保存工作流程操作
        IdentityService is = engine.getIdentityService();
        // 添加用户组
        org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername());
        Group tGroup = new GroupEntityImpl();
        tGroup.setId("tGroup");
        userService.saveRel(is, userInfo, tGroup);
        operaterLogService.add("添加教师成功,教师名称:"+user.getUsername());
        return Message.success();
    }


    /**
     * 修改教师操作
     * @param user
     * @return
     */
    @PostMapping("/editSaveStu")
    @ApiOperation("修改教师接口")
    @PreAuthorize("hasRole('管理员')")
    @ResponseBody
    public Message editSaveStu(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("请填写手机号");
        }
        User userByUserName = userService.findUserByUserName(user.getUsername());
        if(userByUserName!=null){
            if(!userByUserName.getId().equals(user.getId())){
                return Message.error("该用户名已存在");
            }
        }
        try {
            userService.editSaveUser(user);
            operaterLogService.add("编辑教师成功,教师名称:"+user.getUsername());
            return Message.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Message.error("教师信息编辑失败");
        }

    }


}

学生管理接口控制器:

@RequestMapping("/student")
@Controller
@Api(tags = "学生管理接口")
public class StudentController {

    @Autowired
    private IUserService userService;

    @Autowired
    private ICourseService courseService;

    @Autowired
    private IClassesService classesService;
    @Resource
    private ProcessEngine engine;

    @Autowired
    private IOperaterLogService operaterLogService;

    //老师列表
    //后台查询学生列表
    @RequestMapping("/index")
    public String index(Model model){
        //用户首页
        model.addAttribute("courses",courseService.queryAll());
        model.addAttribute("classes",classesService.queryAll());
        return "views/student/student_list";
    }

    @RequestMapping("/listpage")
    @ResponseBody
    public PageList listpage(UserQuery userQuery){
        userQuery.setType(3L);//2表示老学生
        return  userService.listpage(userQuery);
    }

    /**
     * 添加学生操作
     * @param user
     * @return
     */
    @PostMapping("/addSaveStu")
    @ApiOperation("添加学生接口")
    @PreAuthorize("hasRole('管理员')")
    @ResponseBody
    public Message addSaveStudent(User user){
        if(StringUtils.isEmpty(user.getUsername())){
            return Message.error("请填写用户名");
        }
        if(StringUtils.isEmpty(user.getPassword())){
            return Message.error("请填写密码");
        }
        if(StringUtils.isEmpty(user.getEmail())){
            return Message.error("请填写邮箱");
        }
        if(StringUtils.isEmpty(user.getTel())){
            return Message.error("请填写手机号");
        }
        if(StringUtils.isEmpty(user.getStunum())){
            return Message.error("请填写学号");
        }
        User userByUserName = userService.findUserByUserName(user.getUsername());
        if(userByUserName!=null){
            return Message.error("用户名已存在");
        }
        if(userService.findByStuNum(user.getStunum())!=null){
            return Message.error("该学号已存在");
        }
        user.setType(3);
        if(userService.addUser(user)<=0){
            return Message.error("学生添加失败");
        }
        //保存工作流程操作
        IdentityService is = engine.getIdentityService();
        // 添加用户组
        org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername());
        // 添加用户对应的组关系
        Group stuGroup = new GroupEntityImpl();
        stuGroup.setId("stuGroup");
        userService.saveRel(is, userInfo, stuGroup);
        operaterLogService.add("添加学生成功,学生名称:"+user.getUsername());
        return Message.success();
    }



    //修改用户editSaveUser
    @PostMapping("/editSaveStu")
    @ApiOperation("修改学生接口")
    @PreAuthorize("hasRole('管理员')")
    @ResponseBody
    public Message editSaveStu(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("请填写手机号");
        }
        User userByUserName = userService.findUserByUserName(user.getUsername());
        if(userByUserName!=null){
            if(!userByUserName.getId().equals(user.getId())){
                return Message.error("该用户名已存在");
            }
        }
        try {
            userService.editSaveUser(user);
            operaterLogService.add("编辑学生成功,学生名称:"+user.getUsername());
            return Message.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Message.error("学生编辑失败");
        }

    }

    //editSaveStuXk
    @PostMapping("/editSaveStuXk")
    @ApiOperation("修改用户接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "User", value = "学生选课")
    })
    @ResponseBody
    public AjaxResult editSaveStuXk(User user){
        try {
            userService.editSaveXk(user);
            operaterLogService.add("修改学生选课成功,学生名称:"+user.getUsername());
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxResult("修改失败");
    }



}

点击全文阅读


本文链接:http://zhangshiyu.com/post/41220.html

请填写  用户  添加  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1