基于javaweb+mysql的springboot课程评价系统(java+springboot+layui+html+maven+mysql)

基于javaweb+mysql的springboot课程评价系统(java+springboot+layui+html+maven+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SpringBoot课程评价系统(java+springboot+layui+html+maven+mysql)

项目介绍

适合刚接触springboot的同学学习一下的,难度不大,前端使用layui框架,后台springboot+mybatis。代码量较少。 角色分为 学生、教师、管理员,学生可修改密码,先选择课程之后对对应课程的教师做出评价,最后计算出总分入库;

管理员角色包含以下功能:登录,管理员管理,教师管理增删改查,课程管理增删改查,教学指标增删改查,学生增删改查,查看评价等功能。 教师角色包含以下功能:登录,课程管理,教学指标管理,学生管理,收到的评价等功能。 学生角色包含以下功能:登录,修改个人信息,开始评分,选择课程进行评价,查看评分,打分等功能。

环境需要

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+MyBatis

  2. 前端:layui+html

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 将项目中application.properties配置文件中的数据库配置改为自己的配置 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 4. 运行项目,输入localhost:8085 登录 5. 管理员账户:admin 密码:123456 教师账户:jiaoshi 密码:123456

学生账户:student 密码:123456

    public Layui select(@RequestParam(required = false) String courseName, @RequestParam(value = "page",defaultValue = "1") Integer page,
                        @RequestParam(value = "limit",defaultValue = "100") Integer limit) {
        CourseEntityExample example = new CourseEntityExample();
        if (!StringUtils.isEmpty(courseName)) {
            example.or().andCourseNameLike("%"+courseName+"%");
        }
        Long cou = courseEntityMapper.countByExample(example);
        return Layui.data(cou.intValue(), courseEntityMapper.selectByExamplePaging(example, page - 1, limit));
    }

    @RequestMapping("/getCourse")
    public CourseEntity getAdmin(@RequestParam(value = "id") Integer id) {
        return courseEntityMapper.selectByPrimaryKey(id);
    }

    @RequestMapping("/queryTeacherByCourseId")
    public Layui queryTeacherByCourseId(@RequestParam(value = "id") Integer id) {
        CourseTeaEntityExample example = new CourseTeaEntityExample();
        example.or().andCourseIdEqualTo(id);
        List<CourseTeaEntity> courseTeaEntities = courseTeaEntityMapper.selectByExample(example);
        if (courseTeaEntities.size() == 0) {
            return null;
        }
        TeacherEntityExample teacherEntityExample = new TeacherEntityExample();
        teacherEntityExample.or().andTeaIdIn(courseTeaEntities.stream().map(CourseTeaEntity::getTeacherId).collect(Collectors.toList()));
        List<TeacherEntity> teacherEntities = teacherEntityMapper.selectByExample(teacherEntityExample);
        return Layui.data(teacherEntities.size(), teacherEntities);
    }

    @RequestMapping("/updateLoginUser")
    public Integer updateLoginUser(@RequestBody LoginUserDTO loginUserDTO) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String loginType = session.getAttribute("loginUserType").toString();
        UserTypeEnum userTypeEnum = UserTypeEnum.getEventByCode(loginType);
        int userDTO = 0;
        switch (userTypeEnum) {
            case ADMIN:
                AdminEntity adminEntity = new AdminEntity();
                adminEntity.setUserid(loginUserDTO.getId());
                adminEntity.setUsername(loginUserDTO.getUsername());
                adminEntity.setUserpw(loginUserDTO.getPassword());
                userDTO = adminEntityMapper.updateByPrimaryKeySelective(adminEntity);
                break;
            case TEACHER:
            PingjiaxinxiEntityExample entityExample = new PingjiaxinxiEntityExample();
            entityExample.or().andTeaIdEqualTo(teacherId).andStuIdEqualTo(Integer.parseInt(userId));
            Long result = pingjiaxinxiEntityMapper.countByExample(entityExample);
            System.out.println("评价用户身份:"+loginUserType);
            if (result > 0) {
                return Result.ofSuccess(loginUserType);
            }
            pingjiaxinxiEntityMapper.insertSelective(entity);
            return Result.ofSuccess(loginUserType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.ofError(5001,"评价失败");
    }

    @RequestMapping("/listLayui")
    public Layui listLayui(@RequestParam(value = "page") Integer page,
                           @RequestParam(value = "limit") Integer limit) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        PingjiaxinxiEntityExample entityExample = new PingjiaxinxiEntityExample();
        String loginUserId = session.getAttribute("loginUserId").toString();
        String loginUserType = session.getAttribute("loginUserType").toString();
        //如果登录用户为a教师  只能看到他自己的评价信息
        if (loginUserType.equals(UserTypeEnum.TEACHER.getCode())) {
            entityExample.or().andTeaIdEqualTo(Integer.parseInt(loginUserId));
        }
        Long count = pingjiaxinxiEntityMapper.countByExample(entityExample);
        List<PingjiaxinxiEntity> entities = pingjiaxinxiEntityMapper.selectByExamplePaging(entityExample, page, limit);
        List<PJDTO> pjdtoList = new ArrayList<>();
        entities.forEach(o -> {
            PJDTO pjdto = new PJDTO();
            pjdto.setId(o.getId());
            TeacherEntity teacherEntity = teacherEntityMapper.selectByPrimaryKey(o.getTeaId());
            StudentEntity studentEntity = studentEntityMapper.selectByPrimaryKey(o.getStuId());
            pjdto.setStudentName(studentEntity == null ? "" : studentEntity.getStuRealname());
            pjdto.setTeacherName(teacherEntity == null ? "" : teacherEntity.getTeaRealname());
            pjdto.setShijian(o.getShijian());
            pjdto.setZongfen(o.getZongfen());
            pjdtoList.add(pjdto);
        });
        return Layui.data(count.intValue(), pjdtoList);
    }
                    result = 2;
                    session.setAttribute("loginUserType", UserTypeEnum.TEACHER.getCode());
                    session.setAttribute("loginUserId", entity2.getTeaId());
                }
                break;
            case STUDENT:
                StudentEntityExample exampleStu = new StudentEntityExample();
                exampleStu.or().andLoginNameEqualTo(username).andLoginPwEqualTo(password);
                StudentEntity studentEntity = studentEntityMapper.selectOneByExample(exampleStu);
                if (null != studentEntity) {
                    result = 3;
                    session.setAttribute("loginUserType", UserTypeEnum.STUDENT.getCode());
                    session.setAttribute("loginUserId", studentEntity.getStuId());
                }
                break;
            default:
                return 0;
        }
        return result;
    }

    @GetMapping("/getLogin")
    public String getCurrentLoginUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String loginUser = session.getAttribute("loginUserType").toString();
        return loginUser;
    }

    @RequestMapping("/logout")
    public Boolean logout() {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            HttpSession session = request.getSession();
            session.removeAttribute("loginUserType");
            session.removeAttribute("loginUserId");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}

        HttpSession session = request.getSession();
        String loginType = session.getAttribute("loginUserType").toString();
        UserTypeEnum userTypeEnum = UserTypeEnum.getEventByCode(loginType);
        int userDTO = 0;
        switch (userTypeEnum) {
            case ADMIN:
                AdminEntity adminEntity = new AdminEntity();
                adminEntity.setUserid(loginUserDTO.getId());
                adminEntity.setUsername(loginUserDTO.getUsername());
                adminEntity.setUserpw(loginUserDTO.getPassword());
                userDTO = adminEntityMapper.updateByPrimaryKeySelective(adminEntity);
                break;
            case TEACHER:
                TeacherEntity teacherEntity = new TeacherEntity();
                teacherEntity.setTeaId(loginUserDTO.getId());
                teacherEntity.setLoginName(loginUserDTO.getUsername());
                teacherEntity.setLoginPw(loginUserDTO.getPassword());
                userDTO = teacherEntityMapper.updateByPrimaryKey(teacherEntity);
                break;
            case STUDENT:
                StudentEntity studentEntity = new StudentEntity();
                studentEntity.setStuId(loginUserDTO.getId());
                studentEntity.setLoginName(loginUserDTO.getUsername());
                studentEntity.setLoginPw(loginUserDTO.getPassword());
                userDTO = studentEntityMapper.updateByPrimaryKey(studentEntity);
                break;
            default:
                break;
        }
        return userDTO;
    }

    @RequestMapping("/getLoginUser")
    public LoginUserDTO getLoginUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String loginType = session.getAttribute("loginUserType").toString();
        String loginUserId = session.getAttribute("loginUserId").toString();
        UserTypeEnum userTypeEnum = UserTypeEnum.getEventByCode(loginType);
        LoginUserDTO userDTO = new LoginUserDTO();
        switch (userTypeEnum) {
            case ADMIN:
                AdminEntity adminEntity = adminEntityMapper.selectByPrimaryKey(Integer.parseInt(loginUserId));
                userDTO.setId(adminEntity.getUserid());
                userDTO.setUsername(adminEntity.getUsername());
                userDTO.setPassword(adminEntity.getUserpw());
                break;
            case TEACHER:
                TeacherEntity teacherEntity = teacherEntityMapper.selectByPrimaryKey(Integer.parseInt(loginUserId));
                userDTO.setId(teacherEntity.getTeaId());
                userDTO.setUsername(teacherEntity.getLoginName());
                userDTO.setPassword(teacherEntity.getLoginPw());

/**
 * @Description:
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private StudentEntityMapper studentEntityMapper;
    @Autowired
    private AdminEntityMapper adminEntityMapper;
    @Autowired
    private TeacherEntityMapper teacherEntityMapper;

    @PostMapping("/login")
    public Integer login(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password,
                         @RequestParam(value = "userType") String userType) {

        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        UserTypeEnum userTypeEnum = UserTypeEnum.getEventByCode(userType);
        Integer result = 0;
        switch (userTypeEnum) {
            case ADMIN:
                AdminEntityExample example = new AdminEntityExample();
                example.or().andUsernameEqualTo(username).andUserpwEqualTo(password);
                AdminEntity entity = adminEntityMapper.selectOneByExample(example);
                if (null != entity) {
                    result = 1;
                    session.setAttribute("loginUserType", UserTypeEnum.ADMIN.getCode());
                    session.setAttribute("loginUserId", entity.getUserid());
                }
                break;
            case TEACHER:
                TeacherEntityExample exampleTea = new TeacherEntityExample();
                exampleTea.or().andLoginNameEqualTo(username).andLoginPwEqualTo(password);
                TeacherEntity entity2 = teacherEntityMapper.selectOneByExample(exampleTea);
                if (null != entity2) {
                    result = 2;
                    session.setAttribute("loginUserType", UserTypeEnum.TEACHER.getCode());
        }
        if (teaEntities.size() > 0) {
            courseTeaEntityMapper.insertBatch(teaEntities);
        }
        return teacherEntityMapper.insert(entity);
    }

    @PostMapping("/delete")
    public Integer delete(@RequestBody TeacherEntity entity) {
        return teacherEntityMapper.deleteByPrimaryKey(entity.getTeaId());
    }

    @PostMapping("/update")
    public Integer update(@RequestBody TeacherDTO entity) {
        CourseTeaEntityExample example = new CourseTeaEntityExample();
        example.or().andTeacherIdEqualTo(entity.getTeaId());
        //先清空后插入
        courseTeaEntityMapper.deleteByExample(example);
        List<CourseTeaEntity> teaEntities = new ArrayList<>();
        for (int i = 0; i < entity.getCourseIds().length; i++) {
            CourseTeaEntity courseTeaEntity = new CourseTeaEntity();
            courseTeaEntity.setCourseId(entity.getCourseIds()[i]);
            courseTeaEntity.setTeacherId(entity.getTeaId());
            teaEntities.add(courseTeaEntity);
        }
        if (teaEntities.size() > 0) {
            courseTeaEntityMapper.insertBatch(teaEntities);
        }
        return teacherEntityMapper.updateByPrimaryKey(entity);
    }

    @RequestMapping("/select")
    public Layui select(@RequestParam(required = false) String teaRealname, @RequestParam(value = "page") Integer page,
                        @RequestParam(value = "limit") Integer limit) {
        TeacherEntityExample example = new TeacherEntityExample();
        if (!StringUtils.isEmpty(teaRealname)) {
            example.or().andTeaRealnameLike("%"+teaRealname+"%");
        }
        Long cou = teacherEntityMapper.countByExample(example);
        return Layui.data(cou.intValue(), teacherEntityMapper.selectByExamplePaging(example, page - 1, limit));
    }

    @RequestMapping("/getTeacher")
    public TeacherDTO getAdmin(@RequestParam(value = "teaId") Integer teaId) {
        TeacherEntity entity = teacherEntityMapper.selectByPrimaryKey(teaId);
        CourseTeaEntityExample example = new CourseTeaEntityExample();
        example.or().andTeacherIdEqualTo(entity.getTeaId());
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminEntityMapper adminEntityMapper;

    @PostMapping("/add")
    public Integer add(@RequestBody AdminEntity entity) {
        return adminEntityMapper.insert(entity);
    }

    @PostMapping(value = "/delete", consumes = "application/json")
    public Integer delete(@RequestBody AdminEntity entity) {
        return adminEntityMapper.deleteByPrimaryKey(entity.getUserid());
    }

    @PostMapping("/update")
    public Integer update(@RequestBody AdminEntity entity) {
        return adminEntityMapper.updateByPrimaryKey(entity);
    }

    @RequestMapping("/select")
    public Layui select(@RequestParam(required = false) String username,@RequestParam(value = "page")Integer page,
                        @RequestParam(value = "limit")Integer limit) {
        AdminEntityExample example = new AdminEntityExample();
        if (!StringUtils.isEmpty(username)){
            example.or().andUsernameLike("%"+username+"%");
        }
        example.getOrderByClause();
        Long cou = adminEntityMapper.countByExample(example);
        return Layui.data(cou.intValue(), adminEntityMapper.selectByExamplePaging(example, page-1, limit));
    }

    @RequestMapping("/getAdmin")
    public AdminEntity getAdmin(@RequestParam(value="userid")Integer userid) {
        return adminEntityMapper.selectByPrimaryKey(userid);
    }

}

/**
    @PostMapping(value = "/delete", consumes = "application/json")
    public Integer delete(@RequestBody IndexTableEntity entity) {
        return indexTableEntityMapper.deleteByPrimaryKey(entity.getId());
    }

    @PostMapping("/update")
    public Integer update(@RequestBody IndexTableEntity entity) {
        return indexTableEntityMapper.updateByPrimaryKey(entity);
    }

    @RequestMapping("/select")
    public Layui select(@RequestParam(required = false) String indexname, @RequestParam(value = "page") Integer page,
                        @RequestParam(value = "limit") Integer limit) {
        IndexTableEntityExample example = new IndexTableEntityExample();
        IndexTableEntityExample.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(indexname)) {
            criteria.andIndexnameLike("%"+indexname+"%");
        }
        criteria.andParentIdIsNotNull();
        Long cou = indexTableEntityMapper.countByExample(example);
        return Layui.data(cou.intValue(), indexTableEntityMapper.selectByExamplePaging(example, page - 1, limit));
    }

    @RequestMapping("/selectFir")
    public List<IndexTableEntity> selectFir() {
        IndexTableEntityExample example = new IndexTableEntityExample();
        example.or().andParentIdIsNull();
        return indexTableEntityMapper.selectByExample(example);
    }

    @RequestMapping("/selectList")
    public List<IndexTableEntity> selectList() {
        IndexTableEntityExample example = new IndexTableEntityExample();
        example.or().andParentIdIsNotNull();
        return indexTableEntityMapper.selectByExample(example);
    }

    @RequestMapping("/getFirst")
    public IndexTableEntity getAdmin(@RequestParam(value = "id") Integer userid) {
        return indexTableEntityMapper.selectByPrimaryKey(userid);
    }
}
            entityExample.or().andTeaIdEqualTo(teacherId).andStuIdEqualTo(Integer.parseInt(userId));
            Long result = pingjiaxinxiEntityMapper.countByExample(entityExample);
            System.out.println("评价用户身份:"+loginUserType);
            if (result > 0) {
                return Result.ofSuccess(loginUserType);
            }
            pingjiaxinxiEntityMapper.insertSelective(entity);
            return Result.ofSuccess(loginUserType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.ofError(5001,"评价失败");
    }

    @RequestMapping("/listLayui")
    public Layui listLayui(@RequestParam(value = "page") Integer page,
                           @RequestParam(value = "limit") Integer limit) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        PingjiaxinxiEntityExample entityExample = new PingjiaxinxiEntityExample();
        String loginUserId = session.getAttribute("loginUserId").toString();
        String loginUserType = session.getAttribute("loginUserType").toString();
        //如果登录用户为a教师  只能看到他自己的评价信息
        if (loginUserType.equals(UserTypeEnum.TEACHER.getCode())) {
            entityExample.or().andTeaIdEqualTo(Integer.parseInt(loginUserId));
        }
        Long count = pingjiaxinxiEntityMapper.countByExample(entityExample);
        List<PingjiaxinxiEntity> entities = pingjiaxinxiEntityMapper.selectByExamplePaging(entityExample, page, limit);
        List<PJDTO> pjdtoList = new ArrayList<>();
        entities.forEach(o -> {
            PJDTO pjdto = new PJDTO();
            pjdto.setId(o.getId());
            TeacherEntity teacherEntity = teacherEntityMapper.selectByPrimaryKey(o.getTeaId());
            StudentEntity studentEntity = studentEntityMapper.selectByPrimaryKey(o.getStuId());
            pjdto.setStudentName(studentEntity == null ? "" : studentEntity.getStuRealname());
            pjdto.setTeacherName(teacherEntity == null ? "" : teacherEntity.getTeaRealname());
            pjdto.setShijian(o.getShijian());
            pjdto.setZongfen(o.getZongfen());
            pjdtoList.add(pjdto);
        });
        return Layui.data(count.intValue(), pjdtoList);
    }
}

                StudentEntity studentEntity = studentEntityMapper.selectByPrimaryKey(Integer.parseInt(loginUserId));
                userDTO.setId(studentEntity.getStuId());
                userDTO.setUsername(studentEntity.getLoginName());
                userDTO.setPassword(studentEntity.getLoginPw());
                break;
            default:
                break;
        }
        System.out.println(JSONObject.toJSONString(userDTO));
        return userDTO;
    }
}

/**
 * @Description:
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    TeacherEntityMapper teacherEntityMapper;
    @Autowired
    PingjiaxinxiEntityMapper pingjiaxinxiEntityMapper;
    @Autowired
    CourseTeaEntityMapper courseTeaEntityMapper;

    @PostMapping("/add")
    public Integer add(@RequestBody TeacherDTO entity) {
        List<CourseTeaEntity> teaEntities = new ArrayList<>();
        for (int i = 0; i < entity.getCourseIds().length; i++) {
            CourseTeaEntity courseTeaEntity = new CourseTeaEntity();
    @RequestMapping("/selectFir")
    public List<IndexTableEntity> selectFir() {
        IndexTableEntityExample example = new IndexTableEntityExample();
        example.or().andParentIdIsNull();
        return indexTableEntityMapper.selectByExample(example);
    }

    @RequestMapping("/selectList")
    public List<IndexTableEntity> selectList() {
        IndexTableEntityExample example = new IndexTableEntityExample();
        example.or().andParentIdIsNotNull();
        return indexTableEntityMapper.selectByExample(example);
    }

    @RequestMapping("/getFirst")
    public IndexTableEntity getAdmin(@RequestParam(value = "id") Integer userid) {
        return indexTableEntityMapper.selectByPrimaryKey(userid);
    }
}

/**
 * @Description:
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentEntityMapper studentEntityMapper;

    @PostMapping("/add")
    public Integer add(@RequestBody StudentEntity entity) {
        return studentEntityMapper.insert(entity);
    }

    @PostMapping("/delete")
    public Integer delete(@RequestBody StudentEntity entity) {
        return studentEntityMapper.deleteByPrimaryKey(entity.getStuId());
    }

    @PostMapping("/update")
    public Integer update(@RequestBody StudentEntity entity) {
        return studentEntityMapper.updateByPrimaryKey(entity);

    @RequestMapping("/getLoginUser")
    public LoginUserDTO getLoginUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String loginType = session.getAttribute("loginUserType").toString();
        String loginUserId = session.getAttribute("loginUserId").toString();
        UserTypeEnum userTypeEnum = UserTypeEnum.getEventByCode(loginType);
        LoginUserDTO userDTO = new LoginUserDTO();
        switch (userTypeEnum) {
            case ADMIN:
                AdminEntity adminEntity = adminEntityMapper.selectByPrimaryKey(Integer.parseInt(loginUserId));
                userDTO.setId(adminEntity.getUserid());
                userDTO.setUsername(adminEntity.getUsername());
                userDTO.setPassword(adminEntity.getUserpw());
                break;
            case TEACHER:
                TeacherEntity teacherEntity = teacherEntityMapper.selectByPrimaryKey(Integer.parseInt(loginUserId));
                userDTO.setId(teacherEntity.getTeaId());
                userDTO.setUsername(teacherEntity.getLoginName());
                userDTO.setPassword(teacherEntity.getLoginPw());
                break;
            case STUDENT:
                StudentEntity studentEntity = studentEntityMapper.selectByPrimaryKey(Integer.parseInt(loginUserId));
                userDTO.setId(studentEntity.getStuId());
                userDTO.setUsername(studentEntity.getLoginName());
                userDTO.setPassword(studentEntity.getLoginPw());
                break;
            default:
                break;
        }
        System.out.println(JSONObject.toJSONString(userDTO));
        return userDTO;
    }
}


    @PostMapping("/update")
    public Integer update(@RequestBody CourseEntity entity) {
        int i = courseEntityMapper.updateByPrimaryKey(entity);
        if(i != 1){
            i = courseEntityMapper.deleteByPrimaryKey(entity.getId());
        }
        return i;
    }

    @RequestMapping("/select")
    public Layui select(@RequestParam(required = false) String courseName, @RequestParam(value = "page",defaultValue = "1") Integer page,
                        @RequestParam(value = "limit",defaultValue = "100") Integer limit) {
        CourseEntityExample example = new CourseEntityExample();
        if (!StringUtils.isEmpty(courseName)) {
            example.or().andCourseNameLike("%"+courseName+"%");
        }
        Long cou = courseEntityMapper.countByExample(example);
        return Layui.data(cou.intValue(), courseEntityMapper.selectByExamplePaging(example, page - 1, limit));
    }

    @RequestMapping("/getCourse")
    public CourseEntity getAdmin(@RequestParam(value = "id") Integer id) {
        return courseEntityMapper.selectByPrimaryKey(id);
    }

    @RequestMapping("/queryTeacherByCourseId")
    public Layui queryTeacherByCourseId(@RequestParam(value = "id") Integer id) {
        CourseTeaEntityExample example = new CourseTeaEntityExample();
        example.or().andCourseIdEqualTo(id);
        List<CourseTeaEntity> courseTeaEntities = courseTeaEntityMapper.selectByExample(example);
        if (courseTeaEntities.size() == 0) {
            return null;
        }
        TeacherEntityExample teacherEntityExample = new TeacherEntityExample();
        teacherEntityExample.or().andTeaIdIn(courseTeaEntities.stream().map(CourseTeaEntity::getTeacherId).collect(Collectors.toList()));
        List<TeacherEntity> teacherEntities = teacherEntityMapper.selectByExample(teacherEntityExample);
        return Layui.data(teacherEntities.size(), teacherEntities);
    }

    @RequestMapping("/updateLoginUser")
    public Integer updateLoginUser(@RequestBody LoginUserDTO loginUserDTO) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String loginType = session.getAttribute("loginUserType").toString();
        UserTypeEnum userTypeEnum = UserTypeEnum.getEventByCode(loginType);
        int userDTO = 0;
        switch (userTypeEnum) {
            case ADMIN:
                AdminEntity adminEntity = new AdminEntity();
                adminEntity.setUserid(loginUserDTO.getId());
                adminEntity.setUsername(loginUserDTO.getUsername());
                adminEntity.setUserpw(loginUserDTO.getPassword());
                userDTO = adminEntityMapper.updateByPrimaryKeySelective(adminEntity);

    @RequestMapping("/listLayui")
    public Layui listLayui(@RequestParam(value = "page") Integer page,
                           @RequestParam(value = "limit") Integer limit) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        PingjiaxinxiEntityExample entityExample = new PingjiaxinxiEntityExample();
        String loginUserId = session.getAttribute("loginUserId").toString();
        String loginUserType = session.getAttribute("loginUserType").toString();
        //如果登录用户为a教师  只能看到他自己的评价信息
        if (loginUserType.equals(UserTypeEnum.TEACHER.getCode())) {
            entityExample.or().andTeaIdEqualTo(Integer.parseInt(loginUserId));
        }
        Long count = pingjiaxinxiEntityMapper.countByExample(entityExample);
        List<PingjiaxinxiEntity> entities = pingjiaxinxiEntityMapper.selectByExamplePaging(entityExample, page, limit);
        List<PJDTO> pjdtoList = new ArrayList<>();
        entities.forEach(o -> {
            PJDTO pjdto = new PJDTO();
            pjdto.setId(o.getId());
            TeacherEntity teacherEntity = teacherEntityMapper.selectByPrimaryKey(o.getTeaId());
            StudentEntity studentEntity = studentEntityMapper.selectByPrimaryKey(o.getStuId());
            pjdto.setStudentName(studentEntity == null ? "" : studentEntity.getStuRealname());
            pjdto.setTeacherName(teacherEntity == null ? "" : teacherEntity.getTeaRealname());
            pjdto.setShijian(o.getShijian());
            pjdto.setZongfen(o.getZongfen());
            pjdtoList.add(pjdto);
        });
        return Layui.data(count.intValue(), pjdtoList);
    }
}

/**
        IndexTableEntityExample example = new IndexTableEntityExample();
        example.or().andParentIdIsNotNull();
        return indexTableEntityMapper.selectByExample(example);
    }

    @RequestMapping("/getFirst")
    public IndexTableEntity getAdmin(@RequestParam(value = "id") Integer userid) {
        return indexTableEntityMapper.selectByPrimaryKey(userid);
    }
}

/**
 * @Description:
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentEntityMapper studentEntityMapper;

    @PostMapping("/add")
    public Integer add(@RequestBody StudentEntity entity) {
        return studentEntityMapper.insert(entity);
    }

    @PostMapping("/delete")
    public Integer delete(@RequestBody StudentEntity entity) {
        return studentEntityMapper.deleteByPrimaryKey(entity.getStuId());
    }

    @PostMapping("/update")
    public Integer update(@RequestBody StudentEntity entity) {
        return studentEntityMapper.updateByPrimaryKey(entity);
    }

    @RequestMapping("/select")
    public Layui select(@RequestParam(required = false) String stuRealname, @RequestParam(value = "page") Integer page,
                        @RequestParam(value = "limit") Integer limit) {
        StudentEntityExample example = new StudentEntityExample();
        if (!StringUtils.isEmpty(stuRealname)){
            example.or().andStuRealnameLike("%"+stuRealname+"%");
        //如果登录用户为a教师  只能看到他自己的评价信息
        if (loginUserType.equals(UserTypeEnum.TEACHER.getCode())) {
            entityExample.or().andTeaIdEqualTo(Integer.parseInt(loginUserId));
        }
        Long count = pingjiaxinxiEntityMapper.countByExample(entityExample);
        List<PingjiaxinxiEntity> entities = pingjiaxinxiEntityMapper.selectByExamplePaging(entityExample, page, limit);
        List<PJDTO> pjdtoList = new ArrayList<>();
        entities.forEach(o -> {
            PJDTO pjdto = new PJDTO();
            pjdto.setId(o.getId());
            TeacherEntity teacherEntity = teacherEntityMapper.selectByPrimaryKey(o.getTeaId());
            StudentEntity studentEntity = studentEntityMapper.selectByPrimaryKey(o.getStuId());
            pjdto.setStudentName(studentEntity == null ? "" : studentEntity.getStuRealname());
            pjdto.setTeacherName(teacherEntity == null ? "" : teacherEntity.getTeaRealname());
            pjdto.setShijian(o.getShijian());
            pjdto.setZongfen(o.getZongfen());
            pjdtoList.add(pjdto);
        });
        return Layui.data(count.intValue(), pjdtoList);
    }
}

/**
 * @Description:
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private StudentEntityMapper studentEntityMapper;
    @Autowired
    private AdminEntityMapper adminEntityMapper;
        return studentEntityMapper.updateByPrimaryKey(entity);
    }

    @RequestMapping("/select")
    public Layui select(@RequestParam(required = false) String stuRealname, @RequestParam(value = "page") Integer page,
                        @RequestParam(value = "limit") Integer limit) {
        StudentEntityExample example = new StudentEntityExample();
        if (!StringUtils.isEmpty(stuRealname)){
            example.or().andStuRealnameLike("%"+stuRealname+"%");
        }
        Long cou = studentEntityMapper.countByExample(example);
        return Layui.data(cou.intValue(), studentEntityMapper.selectByExamplePaging(example, page - 1, limit));
    }

    @RequestMapping("/getStudent")
    public StudentEntity getAdmin(@RequestParam(value="stuId")Integer stuId) {
        return studentEntityMapper.selectByPrimaryKey(stuId);
    }
}

/**
 * @Description:
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminEntityMapper adminEntityMapper;

    @PostMapping("/add")
    public Integer add(@RequestBody AdminEntity entity) {
        return adminEntityMapper.insert(entity);
    }

    @PostMapping(value = "/delete", consumes = "application/json")
    public Integer delete(@RequestBody AdminEntity entity) {
        return adminEntityMapper.deleteByPrimaryKey(entity.getUserid());
    }

    @PostMapping("/update")
    public Integer update(@RequestBody AdminEntity entity) {

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值