登录功能
修改Login.vue
在管理员下面添加学生端和教师端登录
XML <el-option value="TEACHER" label="教师"></el-option> <el-option value="STUDENT" label="学生"></el-option>
|

WebController
修改登录功能
SQL /** * 登录 */ @PostMapping("/login") public Result login(@RequestBody Account account) { if ("ADMIN".equals(account.getRole())) { return Result.success(adminService.login(account)); } if ("TEACHER".equals(account.getRole())) { return Result.success(teacherService.login(account)); } if ("STUDENT".equals(account.getRole())) { return Result.success(studentService.login(account)); } return Result.success(); }
|
TeacherServiceImpl
Java @Override public Teacher login(Account account) { Teacher teacher = teacherMapper.selectByUsername(account.getUsername()); if (ObjectUtil.isNull(teacher)){ throw new CustomException("用户不存在"); } if (!account.getPassword().equals(teacher.getPassword())){ throw new CustomException("账号或密码错误"); } return teacher; }
|
StudentServiceImpl
Java @Override public Student login(Account account) { Student student = studentMapper.selectByUsername(account.getUsername()); if (ObjectUtil.isNull(student)) { throw new CustomException("用户不存在"); } if (!account.getPassword().equals(student.getPassword())) { throw new CustomException("账号或密码错误"); } return student; }
|
用户管理模块权限
Manager.vue
教师和学生登录后不能显示用户管理模块,修改Manager.vue如下

TypeScript <el-sub-menu index="2" v-if="data.user.role === 'ADMIN'">
|
注册功能
WebController
修改注册功能
TypeScript /** * 注册 */ @PostMapping("/register") public Result register(@RequestBody Account account) { studentService.register(account); return Result.success(); }
|
StudentServiceImpl
TypeScript @Override public void register(Account account) { Student student = new Student(); student.setUsername(account.getUsername()); student.setPassword(account.getPassword()); add(student); }
|
个人资料功能
Manager.vue
修改个人资料

代码
XML <el-menu-item v-if="data.user.role === 'ADMIN'" index="/person"><el-icon><User /></el-icon><span>个人资料</span></el-menu-item> <el-menu-item v-if="data.user.role === 'TEACHER'" index="/tPerson"><el-icon><User /></el-icon><span>个人资料</span></el-menu-item> <el-menu-item v-if="data.user.role === 'STUDENT'" index="/sPerson"><el-icon><User /></el-icon><span>个人资料</span></el-menu-item>
|
路由添加
修改router/index.js,添加对应路由

TypeScript { path: 'tPerson', component: () => import('@/views/manager/TPerson.vue')}, { path: 'sPerson', component: () => import('@/views/manager/SPerson.vue')},
|
添加组件
TPerson.vue
在views/manager中添加TPerson.vue
[TPerson.vue]
SPerson.vue
在views/manager中添加SPerson.vue
[SPerson.vue]
后端
StundentController
SQL /** * 根据id查询 */ @GetMapping("/selectById/{id}") public Result selectById(@PathVariable Integer id) { Student student = studentService.selectById(id); return Result.success(student); }
|
StudentServiceImpl
TypeScript @Override public Student selectById(Integer id) { return studentMapper.selectById(id); }
|
StudentMapper
TypeScript @Select("SELECT s.*,c.`name` collegeName FROM student s LEFT JOIN " + "college c ON s.college_id=c.id WHERE s.id=#{id}") Student selectById(Integer id);
|
修改密码功能
WebController
SQL /** * 修改密码 */ @PutMapping("/updatePassword") public Result updatePassword(@RequestBody Account account) { if ("ADMIN".equals(account.getRole())) { adminService.updatePassword(account); } if ("TEACHER".equals(account.getRole())) { teacherService.updatePassword(account); } if ("STUDENT".equals(account.getRole())) { studentService.updatePassword(account); } return Result.success(); }
|
StudentServiceImpl
Java @Override public void updatePassword(Account account) { //根据账号获取用户 Student student = studentMapper.selectByUsername(account.getUsername()); if (ObjectUtil.isNull(student)) { throw new CustomException("用户不存在"); } if (!account.getPassword().equals(student.getPassword())) { throw new CustomException("原密码错误"); } student.setPassword(account.getNewPassword()); studentMapper.updateById(student); }
|
TeacherServiceImpl
Java @Override public void updatePassword(Account account) { //根据账号获取用户 Teacher teacher = teacherMapper.selectByUsername(account.getUsername()); if (ObjectUtil.isNull(teacher)) { throw new CustomException("用户不存在"); } if (!account.getPassword().equals(teacher.getPassword())) { throw new CustomException("原密码错误"); } teacher.setPassword(account.getNewPassword()); teacherMapper.updateById(teacher); }
|
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
评论(0)