Bootstrap

Java项目:学生会管理系统(java+SpringBoot+Thymeleaf+html+layui+bootstrap+maven+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.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

6.数据库:MySql 5.7版本;

技术栈

1. 后端:SpringBoot

2. 前端:Thymeleaf+html+layui+jQuery+bootstrap

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中application.yml及activiti.cfg.xml配置文件中的数据库配置改为自己的配置;
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
4. 运行项目,输入localhost:8085 登录

 

 

 

 

 

后台用户管理控制器:

/**
 * 后台用户管理控制器
 */
@RequestMapping("/admin/user")
@Component
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;
    @Autowired
    private OperaterLogService operaterLogService;
    /**
     * 用户列表页面
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, User user, PageBean<User> pageBean){
        model.addAttribute("usernmae",user.getUsername());
        model.addAttribute("pageBean",userService.findList(user,pageBean));
        model.addAttribute("title","用户列表");
        return "admin/user/list";
    }


    /**
     * 用户添加页面
     * @param model
     * @param
     * @return
     */
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add(Model model){
        List<Role> all = roleService.findAll();
        model.addAttribute("roles",all);
        return "admin/user/add";
    }

    @ResponseBody
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Boolean> add(Model model,User user){
        //用统一验证实体方法验证是否合法
        CodeMsg validate = ValidateEntityUtil.validate(user);
        if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
            return Result.error(validate);
        }
        //判断用户的角色是否选择
        if(user.getRole()==null ||user.getRole().getId()==null){
            return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
        }
        //没有ID 传个0进去 0不是Long类型 所以加个0l L
        if(userService.isExistUsername(user.getUsername(),0l)){
            return Result.error(CodeMsg.ADMIN_USER_NAME_EXIST);
        }
        //到这说明一切符合条件进行数据库新增
        if(userService.save(user)==null){
            return Result.error(CodeMsg.ADMIN_USER_ADD_ERROR);
        }
        operaterLogService.add("添加用户,用户名:"+user.getUsername());
        return Result.success(true);
    }

    /**
     * 用户编辑页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit",method = RequestMethod.GET)
    public String edit(Model model,@RequestParam(name = "id",required = true) Long id){
        model.addAttribute("user",userService.find(id));
        model.addAttribute("roles",roleService.findAll());
        return "admin/user/edit";
    }

    /**
     * 编辑用户信息表单提交处理
     * @param user
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public Result<Boolean> edit(User user){
        //用统一验证实体方法验证是否合法
        CodeMsg validate = ValidateEntityUtil.validate(user);
        if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
            return Result.error(validate);
        }
        //判断用户的角色是否选择
        if(user.getRole()==null ||user.getRole().getId()==null){
            return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
        }
        if(user.getId()==null||user.getId().longValue()<=0){
            return Result.error(CodeMsg.ADMIN_USER_NO_EXIST);
        }
        //判断数据库user表有没有这个用户名
        if(userService.isExistUsername(user.getUsername(),user.getId().longValue())){
                return Result.error(CodeMsg.ADMIN_USER_NAME_EXIST);
        }
        //将提交的用户信息指定字段复制到已存在的user对象中
        User findbyId = userService.find(user.getId());
        //把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
        BeanUtils.copyProperties(user,findbyId,"id","createTime","updateTime");
        //到这说明一切通过 开始进行数据库编辑
        if(userService.save(findbyId)==null){
            return Result.error(CodeMsg.ADMIN_USER_EDIT_ERROR);
        }
        operaterLogService.add("编辑用户,用户名:"+user.getUsername());
        return Result.success(true);
    }

    @ResponseBody
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public Result<Boolean> delete(@RequestParam(name = "id",required = true) Long id) {
        try {
        userService.delete(id);
        } catch (Exception e){
            return Result.error(CodeMsg.ADMIN_USER_DELETE_ERROR);
        }
        operaterLogService.add("删除用户,id为:"+id);
        return  Result.success(true);
    }
}

后台角色管理控制器: 

/**
 * 后台角色管理控制器
 */
@RequestMapping("/admin/role")
@Controller
public class RoleController {

    @Autowired
    private MenuService menuService;
    private Logger log= LoggerFactory.getLogger(RoleController.class);
    @Autowired
    private OperaterLogService operaterLogService;
    @Autowired
    private RoleService roleService;

    /**
     * 分页搜索角色列表
     * @param model
     * @param role
     * @param pageBean
     * @return
     */
    @RequestMapping(value = "/list")
    public String list(Model model, Role role, PageBean<Role> pageBean){
        model.addAttribute("title","角色列表");
        model.addAttribute("name",role.getName());
        model.addAttribute("pageBean",roleService.findByName(role,pageBean));
        return "admin/role/list";
    }

    /**
     * 角色添加页面
     * @param model
     * @return
     */
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add(Model model){
        List<Menu> all = menuService.findAll();
        model.addAttribute("title","添加角色");
        model.addAttribute("topMenus", MenuUtil.getTopMenus(all));
        model.addAttribute("secondMenus", MenuUtil.getSecondMenus(all));
        model.addAttribute("thirdMenus", MenuUtil.getThirdMenus(all));
        return "admin/role/add";
    }
    /**
     * 角色添加表单提交处理
     * @param role
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Boolean> add(Role role, HttpServletRequest request){
        CodeMsg validate = ValidateEntityUtil.validate(role);
        if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
            return  Result.error(validate);
        }
        if(roleService.save(role)==null){
            return  Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);
        }
        log.info("添加角色["+role+"]");
        operaterLogService.add("添加角色["+role.getName()+"]");
        return Result.success(true);
    }


    /**
     * 角色编辑页面
     * @param id
     * @param model
     * @return
     */
    @RequestMapping(value = "/edit",method = RequestMethod.GET)
    public String edit(@RequestParam(name = "id",required = true) Long id, Model model){
        List<Menu> all = menuService.findAll();
        model.addAttribute("title","添加角色");
        model.addAttribute("topMenus", MenuUtil.getTopMenus(all));
        model.addAttribute("secondMenus", MenuUtil.getSecondMenus(all));
        model.addAttribute("thirdMenus", MenuUtil.getThirdMenus(all));
        Role role = roleService.find(id);
        model.addAttribute("role",role);
        //list转换为数组
        model.addAttribute("authorities", JSONArray.toJSON(role.getAuthorities()).toString());
        return "admin/role/edit";
    }


    /**
     * 角色修改表单提交处理
     * @param role
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public Result<Boolean> edit(Role role, HttpServletRequest request){
        CodeMsg validate = ValidateEntityUtil.validate(role);
        if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
            return  Result.error(validate);
        }
        Role existRole = roleService.find(role.getId());
        if(existRole==null){
            return  Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
        }
        existRole.setName(role.getName());
        existRole.setRemark(role.getRemark());
        existRole.setStatus(role.getStatus());
        existRole.setAuthorities(role.getAuthorities());
        if(roleService.save(existRole)==null){
            return  Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
        }
        log.info("编辑角色["+role+"]");

        operaterLogService.add("编辑角色["+role.getName()+"]");
        return Result.success(true);
    }
    @ResponseBody
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public Result<Boolean> delete(@RequestParam(name = "id",required = true) Long id,HttpServletRequest request){
        try {
            roleService.delete(id);
        }catch (Exception e){
            return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR);
        }
        log.info("删除角色ID["+id+"]");
        operaterLogService.add("删除角色ID["+id+"]");
        return Result.success(true);
    }

}

后台学生管理:

/**
 * 后台学生管理
 */

@RequestMapping("/admin/student/")
@Controller
public class StudentController {
    @Autowired
    private StudentService studentService ;

    @Autowired
    private OperaterLogService operaterLogService;

    /**
     * 学生管理列表
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, Student student, PageBean<Student> pageBean){
        model.addAttribute("pageBean",studentService.findList(student, pageBean));
        model.addAttribute("studentLoginName",student.getLoginName());
        model.addAttribute("title","学生列表");
        return "/admin/student/list";
    }

    /**
     * 后台学生添加页面
     */
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add(){
        return "/admin/student/add";
    }

    /**
     * 后台学生添加信息操作
     */
    @ResponseBody
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Boolean> add(Model model,Student student){
        CodeMsg validate = ValidateEntityUtil.validate(student);
        if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
            return Result.error(validate);
        }
        if(studentService.findByLoginName(student.getLoginName())!=null){
            return Result.error(CodeMsg.ADMIN_STUDENT_ISEXIST_ERROR);
        }
        if(studentService.save(student)==null){
            return Result.error(CodeMsg.ADMIN_STUDENT_ADD_ERROR);
        }
        return Result.success(true);
    }

    /**
     * 编辑学生页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit",method = RequestMethod.GET)
    public String edit(Model model, @RequestParam("id")Long id){
        if(studentService.findById(id)!=null){
            model.addAttribute("student",studentService.findById(id));
        }
        return "/admin/student/edit";
    }


    /**
     * 编辑后台学生信息
     * @param student
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public Result<Boolean> edit(Student student, HttpServletRequest request) {
        //用统一验证实体方法验证是否合法
        CodeMsg validate = ValidateEntityUtil.validate(student);
        if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
            return Result.error(validate);
        }
      //将提交的学生信息指定字段复制到已存在的student对象中
        Student findbyId = studentService.findById(student.getId());
        //把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
        BeanUtils.copyProperties(student, findbyId, "id", "createTime", "updateTime");
        //到这说明一切通过 开始进行数据库编辑
        if (studentService.save(findbyId) == null) {
            return Result.error(CodeMsg.ADMIN_STUDENT_EDIT_ERROR);
        }
        operaterLogService.add("编辑学生,学生姓名:" + student.getStuName());
        return Result.success(true);
    }


    /**
     * 学生删除操作
     * @param ids
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result<Boolean> delete(@RequestParam(name = "ids", required = true) String ids) {
        if (!StringUtils.isEmpty(ids)) {
            String[] splitIds = ids.split(",");
            for (String id : splitIds) {
                Student student = studentService.findById(Long.valueOf(id));
                if (student != null) {
                    try {
                        studentService.delete(Long.valueOf(id));
                        operaterLogService.add("删除学生,id为:" + id);
                    }catch (Exception e){
                        return Result.error(CodeMsg.ADMIN_STUDENT_DELETE_ERROR);
                    }
                }

            }

        }
        return Result.success(true);
    }

}

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

;