基于javaweb+mysql的springboot成绩管理系统(前后端分离+java+vue+springboot+ssm+mysql+maven)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot成绩管理系统(前后端分离+java+vue+springboot+ssm+mysql+maven)
一、项目简述
本系统功能包括: 超豪华成绩管理系统,学生,教师,管理员三类用户集 成,课程表管理,成绩查询,成绩详情数据统计,课程录 入,用户管理,账号管理。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持)。
项目技术: Springboot + Maven + Mybatis + Vue等等组成, B/S模式+ Maven等等。
/**
* Description 管理员账户控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/user/admin")
public class AdminController {
@Autowired
private AdminService adminService;
@PostMapping
public void addAdmin(@RequestBody User user) {
adminService.add(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
adminService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
adminService.update(user);
}
@GetMapping("/getAdminList")
public PagingResult<User> getAdminList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return adminService.getAdminList(rowBounds, condition);
}
}
package com.zjh.sms.controller.Profession;
/**
@Autowired
private TeacherCourseService teacherCourseService;
@PostMapping
public void add(@RequestBody JSONArray teacherCourseInfo) {
List<TeacherCourse> list = JSONObject.parseArray(teacherCourseInfo.toJSONString(), TeacherCourse.class);
teacherCourseService.add(list);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
teacherCourseService.delete(idsList);
}
@PutMapping
public void update(@RequestBody TeacherCourse teacherCourse) {
teacherCourseService.update(teacherCourse);
}
@GetMapping("/getCourseListById/{id}")
public List<TeacherCourse> getCourseListById(@PathVariable("id") String id) {
return teacherCourseService.getCourseListById(id);
}
@GetMapping("/getProfessionInfoByTeacher/{teacherId}")
public List<Map<String, Object>> getProfessionInfo(@PathVariable("teacherId") String teacherId) {
return teacherCourseService.getProfessionInfo(teacherId);
}
@GetMapping("/getProfessionInfoByAdmin")
public List<Map<String, Object>> getProfessionInfoByAdmin() {
return teacherCourseService.getProfessionInfoByAdmin();
}
@GetMapping("/getCourseInfo")
public TeacherCourse getCourseInfo(@RequestParam Map<String, Object> condition) {
return teacherCourseService.getCourseInfo(condition);
}
}
package com.zjh.sms.controller.Score;
@RequestMapping("/api/sms/user/teacher")
public class TeacherController {
@Autowired
private TeacherService teacherService;
@PostMapping
public void addTeacher(@RequestBody User user) {
teacherService.addTeacher(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
teacherService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
teacherService.update(user);
}
@GetMapping("/getTeacherList")
public PagingResult<User> getTeacherList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return teacherService.getTeacherList(rowBounds, condition);
}
}
package com.zjh.sms.controller.User;
/**
* Description 学生账号控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/user/student")
public class StudentController {
@Autowired
private StudentService studentService;
return user;
}
@GetMapping("/edit/password")
public boolean update (@RequestParam Map<String, Object> condition) {
Map<String, Object> map = new HashMap<>();
map.put("username", condition.get("username").toString());
map.put("password", condition.get("password").toString());
map.put("passwordAgain", condition.get("passwordAgain").toString());;
map.put("level", condition.get("level").toString());
return userService.update(map);
}
@GetMapping("/getTree")
public List<Object> getTree () {
return userService.getTree();
}
@PassToken
@GetMapping("/getSilent")
public boolean getSilent () {
return userService.getSilent();
}
@PutMapping("/setSilent/{state}")
public boolean setSilent (@PathVariable("state") Integer state) {
return userService.setSilent(state);
}
}
package com.zjh.sms.controller.TeacherCourse;
/**
* Description 教师课程控制层
if (passToken.required()) {
return true;
}
}
// 获取 token 中的 用户信息
String userValue = null;
try {
userValue = JWT.decode(token).getAudience().get(0);
} catch (JWTDecodeException j) {
throw new RuntimeException("401");
}
Map<String, Object> map = new HashMap<>();
map.put("level", (userValue).substring(0,1));
map.put("id", (userValue).substring(1));
User user = userService.findUser(map);
if (user == null) {
throw new RuntimeException("用户不存在,请重新登录");
}
Date oldTime = JWT.decode(token).getExpiresAt();
Date refreshTime = JWT.decode(refreshToken).getExpiresAt();
long oldDiff = oldTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
long refreshDiff = refreshTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
if (oldDiff <= 0) {
if (refreshDiff <= 0) {
logger.error("=== token 已过期, 请重新登录 ===");
httpServletResponse.sendError(401);
return false;
// throw new RuntimeException("401");
}
}
String newToken = userService.getToken(user, 60* 60 * 1000);
String newRefToken = userService.getToken(user, 24*60*60*1000);
// 更新token
httpServletResponse.setHeader("Authorization", newToken);
httpServletResponse.setHeader("freshToken", newRefToken);
//检查有没有需要用户权限的注解
// if (method.isAnnotationPresent(UserLoginToken.class)) { // 是否使用@UserLoginToken注解
// UserLoginToken userLoginToken = method.getAnnotation(UserLoginToken.class);
// if (userLoginToken.required()) {
}
package com.zjh.sms.controller.TeacherCourse;
/**
* Description 教师课程控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/teacher/course")
public class TeacherCourseController {
@Autowired
private TeacherCourseService teacherCourseService;
@PostMapping
public void add(@RequestBody JSONArray teacherCourseInfo) {
List<TeacherCourse> list = JSONObject.parseArray(teacherCourseInfo.toJSONString(), TeacherCourse.class);
teacherCourseService.add(list);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
teacherCourseService.delete(idsList);
}
@PutMapping
public void update(@RequestBody TeacherCourse teacherCourse) {
teacherCourseService.update(teacherCourse);
}
/**
* Description 拦截器去获取token并验证token
* Author: zjh
**/
@Slf4j
public class AuthenticationInterceptor implements HandlerInterceptor {
private final Log logger = LogFactory.getLog(UploadServiceImpl.class);
@Autowired
UserService userService;
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws Exception {
//通过所有OPTION请求
if(httpServletRequest.getMethod().toUpperCase().equals("OPTIONS")){
return true;
}
String token = httpServletRequest.getHeader("Authorization");// 从 http 请求头中取出 token
String refreshToken = httpServletRequest.getHeader("freshToken");// 从 http 请求头中取出 token
Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
//2.遍历
while(headerNames.hasMoreElements()){
String name = headerNames.nextElement();
//通过请求头的名称获取请求头的值
String value = httpServletRequest.getHeader(name);
System.out.println(name+"----"+value);
}
// 如果不是映射到方法直接通过
**/
@RestController
@RequestMapping("/api/sms/user/admin")
public class AdminController {
@Autowired
private AdminService adminService;
@PostMapping
public void addAdmin(@RequestBody User user) {
adminService.add(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
adminService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
adminService.update(user);
}
@GetMapping("/getAdminList")
public PagingResult<User> getAdminList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return adminService.getAdminList(rowBounds, condition);
}
}
package com.zjh.sms.controller.Profession;
/**
* Description 所有专业控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/profession")
public void afterCompletion(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
Object o, Exception e) throws Exception {
}
}
package com.zjh.sms.controller.Upload;
/**
* Description 上传控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/upload")
public class UploadController {
@Autowired
private UploadService uploadService;
@PostMapping("/headImg")
@ResponseBody
public String upload(MultipartFile file, HttpServletRequest request) throws IOException {
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
// 储存位置
String url = "sms/static/img/";
// 图片名
String ImgName = file.getOriginalFilename();
String uid = UUID.randomUUID().toString();
assert ImgName != null;
// 获取后缀名
String str = ImgName.substring(ImgName.lastIndexOf("."));
// 重定义文件名
RowBounds rowBounds = new RowBounds(offset, limit);
return scoreService.getCourseList(rowBounds, condition);
}
@PostMapping
private void addEntry(@RequestBody JSONArray UserScore) {
List<Score> list = JSONObject.parseArray(UserScore.toJSONString(), Score.class);
scoreService.addEntry(list);
}
@GetMapping("/export")
public List<Course> getExportList (@RequestParam Map<String, Object> condition) {
return scoreService.getExportList(condition);
}
@GetMapping("/getUserNum")
public List<Map<String, Object>> getUserNum (@RequestParam Map<String, Object> condition) {
return scoreService.getUserNum(condition);
}
@GetMapping("/getUserTotal")
public Map<String, Object> getUserTotal (@RequestParam Map<String, Object> condition) {
return scoreService.getUserTotal(condition);
}
}
package com.zjh.sms.config;
/**
* Description 解决vue+spring boot跨域问题
* Author: zjh
**/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
}
@Override
public void postHandle(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
Object o, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
Object o, Exception e) throws Exception {
}
}
package com.zjh.sms.controller.Upload;
/**
* Description 上传控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/upload")
public class UploadController {
@Autowired
private UploadService uploadService;
}
}
return "";
}
@GetMapping("/getHeadImg")
@UserLoginToken
public String getAdminList (@RequestParam Map<String, Object> condition, HttpServletRequest httpServletRequest) {
return uploadService.getHeader(condition);
}
}
package com.zjh.sms.controller.User;
/**
* Description 登陆用户控制层
* Author: zjh
**/
@RestController
@UserLoginToken
@RequestMapping("/api/sms/user")
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/login")
@PassToken
public User getStudentInfo (@RequestParam Map<String, Object> condition) {
Map<String, Object> map = new HashMap<>();
map.put("username", condition.get("username").toString());
map.put("password", condition.get("password").toString());
map.put("level", condition.get("level"));
User user = userService.getStudentInfo(map);
// String token = userService.getToken(user, 60* 60 * 1000); // 有效期1h
String token = userService.getToken(user, 24*60* 60 * 1000);
String refreshToken = userService.getToken(user, 24*60*60*1000); // 有效期一天
user.setToken(token);
user.setRefreshToken(refreshToken);
return user;
}
@GetMapping("/edit/password")
public boolean update (@RequestParam Map<String, Object> condition) {
Map<String, Object> map = new HashMap<>();
map.put("username", condition.get("username").toString());
/**
* Description 学生账号控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/user/student")
public class StudentController {
@Autowired
private StudentService studentService;
@PostMapping
public void addStudent(@RequestBody User user) {
studentService.addStudent(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") String[] ids) {
List<String> idsList = Arrays.asList(ids);
studentService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
studentService.update(user);
}
@GetMapping("/getStudentList")
public PagingResult<User> getStudentList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return studentService.getStudentList(rowBounds, condition);
}
}
package com.zjh.sms.controller.User;
@PutMapping("/setSilent/{state}")
public boolean setSilent (@PathVariable("state") Integer state) {
return userService.setSilent(state);
}
}
package com.zjh.sms.controller.TeacherCourse;
/**
* Description 教师课程控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/teacher/course")
public class TeacherCourseController {
@Autowired
private TeacherCourseService teacherCourseService;
@PostMapping
public void add(@RequestBody JSONArray teacherCourseInfo) {
List<TeacherCourse> list = JSONObject.parseArray(teacherCourseInfo.toJSONString(), TeacherCourse.class);
teacherCourseService.add(list);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
teacherCourseService.delete(idsList);
}
@PutMapping
public void update(@RequestBody TeacherCourse teacherCourse) {
teacherCourseService.update(teacherCourse);
}
@GetMapping("/getCourseListById/{id}")
public List<TeacherCourse> getCourseListById(@PathVariable("id") String id) {
return teacherCourseService.getCourseListById(id);
}
@GetMapping("/getProfessionInfoByTeacher/{teacherId}")
public List<Map<String, Object>> getProfessionInfo(@PathVariable("teacherId") String teacherId) {
//通过请求头的名称获取请求头的值
String value = httpServletRequest.getHeader(name);
System.out.println(name+"----"+value);
}
// 如果不是映射到方法直接通过
if (!(object instanceof HandlerMethod)) {
return true;
}
HandlerMethod handlerMethod = (HandlerMethod) object;
Method method = handlerMethod.getMethod();
//检查是否有passtoken注释,有则跳过认证
if (method.isAnnotationPresent(PassToken.class)) {
PassToken passToken = method.getAnnotation(PassToken.class);
if (passToken.required()) {
return true;
}
}
// 获取 token 中的 用户信息
String userValue = null;
try {
userValue = JWT.decode(token).getAudience().get(0);
} catch (JWTDecodeException j) {
throw new RuntimeException("401");
}
Map<String, Object> map = new HashMap<>();
map.put("level", (userValue).substring(0,1));
map.put("id", (userValue).substring(1));
User user = userService.findUser(map);
if (user == null) {
throw new RuntimeException("用户不存在,请重新登录");
}
Date oldTime = JWT.decode(token).getExpiresAt();
Date refreshTime = JWT.decode(refreshToken).getExpiresAt();
long oldDiff = oldTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
long refreshDiff = refreshTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
if (oldDiff <= 0) {
if (refreshDiff <= 0) {
logger.error("=== token 已过期, 请重新登录 ===");
httpServletResponse.sendError(401);
return false;
// throw new RuntimeException("401");
}
}
String newToken = userService.getToken(user, 60* 60 * 1000);
String newRefToken = userService.getToken(user, 24*60*60*1000);
// 更新token
httpServletResponse.setHeader("Authorization", newToken);
httpServletResponse.setHeader("freshToken", newRefToken);
private PagingResult<Course> getCourseList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return courseService.getCourseList(rowBounds, condition);
}
@GetMapping("/getCourseByMap")
private List<Course> getCourseByMap (@RequestParam Map<String, Object> condition) {
return courseService.getCourseByMap(condition);
}
}
package com.zjh.sms.controller.Timetable;
/**
* Description 课程表控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/timetable")
public class TimetableController {
@Autowired
private TimetableService timetableService;
@PostMapping
public void add(@RequestBody JSONArray WeekCourseList) {
List<WeekCourse> list = JSONObject.parseArray(WeekCourseList.toJSONString(), WeekCourse.class);
timetableService.add(list);
}
@GetMapping("/getTimetable")
public List<WeekCourse> getStudentList (@RequestParam Map<String, Object> condition) {
return timetableService.getTimetable(condition);
}
@GetMapping("/getTimetableByStudent")
public List<WeekCourse> getTimetableByStudent (@RequestParam Map<String, Object> condition) {
return timetableService.getTimetableByStudent(condition);
}
@GetMapping("/getTimetableByTeacher")
map.put("level", (userValue).substring(0,1));
map.put("id", (userValue).substring(1));
User user = userService.findUser(map);
if (user == null) {
throw new RuntimeException("用户不存在,请重新登录");
}
Date oldTime = JWT.decode(token).getExpiresAt();
Date refreshTime = JWT.decode(refreshToken).getExpiresAt();
long oldDiff = oldTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
long refreshDiff = refreshTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
if (oldDiff <= 0) {
if (refreshDiff <= 0) {
logger.error("=== token 已过期, 请重新登录 ===");
httpServletResponse.sendError(401);
return false;
// throw new RuntimeException("401");
}
}
String newToken = userService.getToken(user, 60* 60 * 1000);
String newRefToken = userService.getToken(user, 24*60*60*1000);
// 更新token
httpServletResponse.setHeader("Authorization", newToken);
httpServletResponse.setHeader("freshToken", newRefToken);
//检查有没有需要用户权限的注解
// if (method.isAnnotationPresent(UserLoginToken.class)) { // 是否使用@UserLoginToken注解
// UserLoginToken userLoginToken = method.getAnnotation(UserLoginToken.class);
// if (userLoginToken.required()) {
// 执行认证
if (token == null) {
throw new RuntimeException("=== 无token,请重新登录 ===");
}
// 利用用户密码,解密验证 token
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(user.getPassword())).build();
try {
jwtVerifier.verify(token);
} catch (JWTVerificationException e) {
logger.error("=== token验证失败 ===");
httpServletResponse.sendError(401);
return false;
// throw new RuntimeException("401");
}
// return true;
// }
// }
return true;
}
@Override
public void postHandle(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
/**
* Description 教师账号控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/user/teacher")
public class TeacherController {
@Autowired
private TeacherService teacherService;
@PostMapping
public void addTeacher(@RequestBody User user) {
teacherService.addTeacher(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
teacherService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
teacherService.update(user);
}
@GetMapping("/getTeacherList")
public PagingResult<User> getTeacherList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return teacherService.getTeacherList(rowBounds, condition);
}
}
package com.zjh.sms.controller.User;
**/
@RestController
@RequestMapping("/api/sms/user/student")
public class StudentController {
@Autowired
private StudentService studentService;
@PostMapping
public void addStudent(@RequestBody User user) {
studentService.addStudent(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") String[] ids) {
List<String> idsList = Arrays.asList(ids);
studentService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
studentService.update(user);
}
@GetMapping("/getStudentList")
public PagingResult<User> getStudentList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return studentService.getStudentList(rowBounds, condition);
}
}
package com.zjh.sms.controller.User;
/**
* Description 管理员账户控制层
* Author: zjh
if (user == null) {
throw new RuntimeException("用户不存在,请重新登录");
}
Date oldTime = JWT.decode(token).getExpiresAt();
Date refreshTime = JWT.decode(refreshToken).getExpiresAt();
long oldDiff = oldTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
long refreshDiff = refreshTime.getTime() - new Date().getTime();//这样得到的差值是毫秒级别
if (oldDiff <= 0) {
if (refreshDiff <= 0) {
logger.error("=== token 已过期, 请重新登录 ===");
httpServletResponse.sendError(401);
return false;
// throw new RuntimeException("401");
}
}
String newToken = userService.getToken(user, 60* 60 * 1000);
String newRefToken = userService.getToken(user, 24*60*60*1000);
// 更新token
httpServletResponse.setHeader("Authorization", newToken);
httpServletResponse.setHeader("freshToken", newRefToken);
//检查有没有需要用户权限的注解
// if (method.isAnnotationPresent(UserLoginToken.class)) { // 是否使用@UserLoginToken注解
// UserLoginToken userLoginToken = method.getAnnotation(UserLoginToken.class);
// if (userLoginToken.required()) {
// 执行认证
if (token == null) {
throw new RuntimeException("=== 无token,请重新登录 ===");
}
// 利用用户密码,解密验证 token
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(user.getPassword())).build();
try {
jwtVerifier.verify(token);
} catch (JWTVerificationException e) {
logger.error("=== token验证失败 ===");
httpServletResponse.sendError(401);
return false;
// throw new RuntimeException("401");
}
// return true;
// }
RowBounds rowBounds = new RowBounds(offset, limit);
return scoreService.getCourseList(rowBounds, condition);
}
@PostMapping
private void addEntry(@RequestBody JSONArray UserScore) {
List<Score> list = JSONObject.parseArray(UserScore.toJSONString(), Score.class);
scoreService.addEntry(list);
}
@GetMapping("/export")
public List<Course> getExportList (@RequestParam Map<String, Object> condition) {
return scoreService.getExportList(condition);
}
@GetMapping("/getUserNum")
public List<Map<String, Object>> getUserNum (@RequestParam Map<String, Object> condition) {
return scoreService.getUserNum(condition);
}
@GetMapping("/getUserTotal")
public Map<String, Object> getUserTotal (@RequestParam Map<String, Object> condition) {
return scoreService.getUserTotal(condition);
}
}
package com.zjh.sms.config;
/**
* Description 解决vue+spring boot跨域问题
* Author: zjh
**/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
teacherService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
teacherService.update(user);
}
@GetMapping("/getTeacherList")
public PagingResult<User> getTeacherList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return teacherService.getTeacherList(rowBounds, condition);
}
}
package com.zjh.sms.controller.User;
/**
* Description 学生账号控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/user/student")
public class StudentController {
@Autowired
private StudentService studentService;
public class AdminController {
@Autowired
private AdminService adminService;
@PostMapping
public void addAdmin(@RequestBody User user) {
adminService.add(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
adminService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
adminService.update(user);
}
@GetMapping("/getAdminList")
public PagingResult<User> getAdminList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return adminService.getAdminList(rowBounds, condition);
}
}
package com.zjh.sms.controller.Profession;
/**
* Description 所有专业控制层
* Author: zjh
**/
@RestController
@RequestMapping("/api/sms/profession")
public class ProfessionController {
@Autowired
@Slf4j
public class AuthenticationInterceptor implements HandlerInterceptor {
private final Log logger = LogFactory.getLog(UploadServiceImpl.class);
@Autowired
UserService userService;
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws Exception {
//通过所有OPTION请求
if(httpServletRequest.getMethod().toUpperCase().equals("OPTIONS")){
return true;
}
String token = httpServletRequest.getHeader("Authorization");// 从 http 请求头中取出 token
String refreshToken = httpServletRequest.getHeader("freshToken");// 从 http 请求头中取出 token
Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
//2.遍历
while(headerNames.hasMoreElements()){
String name = headerNames.nextElement();
//通过请求头的名称获取请求头的值
String value = httpServletRequest.getHeader(name);
System.out.println(name+"----"+value);
}
// 如果不是映射到方法直接通过
if (!(object instanceof HandlerMethod)) {
return true;
}
HandlerMethod handlerMethod = (HandlerMethod) object;
Method method = handlerMethod.getMethod();
//检查是否有passtoken注释,有则跳过认证
if (method.isAnnotationPresent(PassToken.class)) {
PassToken passToken = method.getAnnotation(PassToken.class);
if (passToken.required()) {
return true;
}
}
// 获取 token 中的 用户信息
String userValue = null;
try {
userValue = JWT.decode(token).getAudience().get(0);
} catch (JWTDecodeException j) {
throw new RuntimeException("401");
}
Map<String, Object> map = new HashMap<>();
map.put("level", (userValue).substring(0,1));
map.put("id", (userValue).substring(1));
User user = userService.findUser(map);
if (user == null) {
throw new RuntimeException("用户不存在,请重新登录");
}
@RestController
@RequestMapping("/api/sms/user/teacher")
public class TeacherController {
@Autowired
private TeacherService teacherService;
@PostMapping
public void addTeacher(@RequestBody User user) {
teacherService.addTeacher(user);
}
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") Integer[] ids) {
List<Integer> idsList = Arrays.asList(ids);
teacherService.delete(idsList);
}
@PutMapping
public void update(@RequestBody User user) {
teacherService.update(user);
}
@GetMapping("/getTeacherList")
public PagingResult<User> getTeacherList (@RequestParam Map<String, Object> condition,
@RequestParam(required = false, name = "$limit", defaultValue = "10") Integer limit,
@RequestParam(required = false, name = "$offset", defaultValue = "0") Integer offset) {
RowBounds rowBounds = new RowBounds(offset, limit);
return teacherService.getTeacherList(rowBounds, condition);
}
}
package com.zjh.sms.controller.User;
/**
* Description 学生账号控制层
* Author: zjh
**/
@RestController