基于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版本;
技术栈
-
后端:SpringBoot+MyBatis
-
前端:layui+html
使用说明
- 使用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
@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;
}
}
/**
* @Description:
*/
@RestController
@RequestMapping("/first")
public class IndexController {
@Autowired
private IndexTableEntityMapper indexTableEntityMapper;
@PostMapping("/add")
public Integer add(@RequestBody IndexTableEntity entity) {
if (StringUtils.isEmpty(entity.getParentId())) {
entity.setParentId(null);
}
return indexTableEntityMapper.insert(entity);
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;
}
}
/**
* @Description:
*/
@RestController
@RequestMapping("/first")
public class IndexController {
@Autowired
private IndexTableEntityMapper indexTableEntityMapper;
@PostMapping("/add")
public Integer add(@RequestBody IndexTableEntity entity) {
if (StringUtils.isEmpty(entity.getParentId())) {
entity.setParentId(null);
/**
* @Description: 评价信息控制类
*/
@RestController
@RequestMapping("/pj")
public class PJController {
@Autowired
PingjiaxinxiEntityMapper pingjiaxinxiEntityMapper;
@Autowired
private StudentEntityMapper studentEntityMapper;
@Autowired
private TeacherEntityMapper teacherEntityMapper;
@RequestMapping("/add")
public Result insert(@RequestParam(value = "teacherId") Integer teacherId,
@RequestParam(value = "lastResult") Integer lastResult) {
try {
PingjiaxinxiEntity entity = new PingjiaxinxiEntity();
entity.setShijian(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
entity.setTeaId(teacherId);
entity.setZongfen(lastResult);
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = request.getSession();
String userId = session.getAttribute("loginUserId").toString();
String loginUserType = session.getAttribute("loginUserType").toString();
entity.setStuId(Integer.parseInt(userId));
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();
if (!StringUtils.endsWithIgnoreCase(UserTypeEnum.STUDENT.getCode(), loginType)) {
return true;
}
PingjiaxinxiEntityExample example = new PingjiaxinxiEntityExample();
example.or().andStuIdEqualTo(stuId).andTeaIdEqualTo(teaId);
return pingjiaxinxiEntityMapper.selectByExample(example).size() > 0;
}
}
/**
* @Description: 评价信息控制类
*/
@RestController
@RequestMapping("/pj")
public class PJController {
@Autowired
PingjiaxinxiEntityMapper pingjiaxinxiEntityMapper;
@Autowired
private StudentEntityMapper studentEntityMapper;
@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());
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")
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;
}
}
/**
* @Description:
*/
@RestController
@RequestMapping("/first")
public class IndexController {
@Autowired
private IndexTableEntityMapper indexTableEntityMapper;
@PostMapping("/add")
public Integer add(@RequestBody IndexTableEntity entity) {
if (StringUtils.isEmpty(entity.getParentId())) {
entity.setParentId(null);
}
return indexTableEntityMapper.insert(entity);
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:
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();
}
@RequestMapping("/getTeacher")
public TeacherDTO getAdmin(@RequestParam(value = "teaId") Integer teaId) {
TeacherEntity entity = teacherEntityMapper.selectByPrimaryKey(teaId);
CourseTeaEntityExample example = new CourseTeaEntityExample();
example.or().andTeacherIdEqualTo(entity.getTeaId());
List<CourseTeaEntity> courseTeaEntities = courseTeaEntityMapper.selectByExample(example);
Integer[] arr = new Integer[courseTeaEntities.size()];
for (int i = 0; i < courseTeaEntities.size(); i++) {
arr[i] = courseTeaEntities.get(i).getCourseId();
}
TeacherDTO dto = new TeacherDTO();
dto.setCourseIds(arr);
dto.setLoginName(entity.getLoginName());
dto.setLoginPw(entity.getLoginPw());
dto.setTeaId(entity.getTeaId());
dto.setDel(entity.getDel());
dto.setTeaAge(entity.getTeaAge());
dto.setTeaBianhao(entity.getTeaBianhao());
dto.setTeaRealname(entity.getTeaRealname());
dto.setTeaSex(entity.getTeaSex());
return dto;
}
/**
* 若存在--提示已经评论过
*
* @param teaId
* @return
*/
@RequestMapping("/exit")
public Boolean exit(@RequestParam(value = "teaId") Integer teaId) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = request.getSession();
//学生id
Integer stuId = Integer.parseInt(session.getAttribute("loginUserId").toString());
String loginType = session.getAttribute("loginUserType").toString();
if (!StringUtils.endsWithIgnoreCase(UserTypeEnum.STUDENT.getCode(), loginType)) {
return true;
}
PingjiaxinxiEntityExample example = new PingjiaxinxiEntityExample();
example.or().andStuIdEqualTo(stuId).andTeaIdEqualTo(teaId);
return pingjiaxinxiEntityMapper.selectByExample(example).size() > 0;
}
}
@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());
List<CourseTeaEntity> courseTeaEntities = courseTeaEntityMapper.selectByExample(example);
Integer[] arr = new Integer[courseTeaEntities.size()];
for (int i = 0; i < courseTeaEntities.size(); i++) {
arr[i] = courseTeaEntities.get(i).getCourseId();
@Autowired
private IndexTableEntityMapper indexTableEntityMapper;
@PostMapping("/add")
public Integer add(@RequestBody IndexTableEntity entity) {
if (StringUtils.isEmpty(entity.getParentId())) {
entity.setParentId(null);
}
return indexTableEntityMapper.insert(entity);
}
@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();
* @Description: 评价信息控制类
*/
@RestController
@RequestMapping("/pj")
public class PJController {
@Autowired
PingjiaxinxiEntityMapper pingjiaxinxiEntityMapper;
@Autowired
private StudentEntityMapper studentEntityMapper;
@Autowired
private TeacherEntityMapper teacherEntityMapper;
@RequestMapping("/add")
public Result insert(@RequestParam(value = "teacherId") Integer teacherId,
@RequestParam(value = "lastResult") Integer lastResult) {
try {
PingjiaxinxiEntity entity = new PingjiaxinxiEntity();
entity.setShijian(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
entity.setTeaId(teacherId);
entity.setZongfen(lastResult);
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = request.getSession();
String userId = session.getAttribute("loginUserId").toString();
String loginUserType = session.getAttribute("loginUserType").toString();
entity.setStuId(Integer.parseInt(userId));
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,
@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);
}
}
/**
* @Description:
*/
@RestController
@RequestMapping("/login")
public class LoginController {
/**
* @Description:
*/
@RestController
@RequestMapping("/first")
public class IndexController {
@Autowired
private IndexTableEntityMapper indexTableEntityMapper;
@PostMapping("/add")
public Integer add(@RequestBody IndexTableEntity entity) {
if (StringUtils.isEmpty(entity.getParentId())) {
entity.setParentId(null);
}
return indexTableEntityMapper.insert(entity);
}
@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();
/**
* @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();
courseTeaEntity.setCourseId(entity.getCourseIds()[i]);
courseTeaEntity.setTeacherId(entity.getTeaId());
teaEntities.add(courseTeaEntity);
}
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();
public Integer add(@RequestBody CourseEntity entity) {
return courseEntityMapper.insert(entity);
}
@PostMapping(value = "/delete", consumes = "application/json")
public Integer delete(@RequestBody CourseEntity entity) {
return courseEntityMapper.deleteByPrimaryKey(entity.getId());
}
@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();
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;
}
}
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;
}
}
/**
* @Description:
*/
@RestController
@RequestMapping("/first")
public class IndexController {
@Autowired
private IndexTableEntityMapper indexTableEntityMapper;