毕业设计|基于SpringBoot+Vue的新生报道(一)https://developer.aliyun.com/article/1423958
四,核心代码展示
4.1 ArriveschoolController
@RestController @RequestMapping("/arriveschool") public class ArriveschoolController { @Resource private IArriveschoolService arriveschoolService; @Resource IUserService userService; private final String now = DateUtil.now(); // 新增或者更新 @PostMapping public Result save(@RequestBody Arriveschool arriveschool) { if (arriveschool.getId() == null) { Integer userid = arriveschool.getUserid(); QueryWrapper<Arriveschool> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("userid",userid); final Arriveschool one = arriveschoolService.getOne(queryWrapper); if(null != one){ return Result.error("400","只能提交一次,不能重复提交"); } } arriveschoolService.saveOrUpdate(arriveschool); return Result.success(); } @DeleteMapping("/{id}") public Result delete(@PathVariable Integer id) { arriveschoolService.removeById(id); return Result.success(); } @PostMapping("/del/batch") public Result deleteBatch(@RequestBody List<Integer> ids) { arriveschoolService.removeByIds(ids); return Result.success(); } @GetMapping public Result findAll() { return Result.success(arriveschoolService.list()); } @GetMapping("/{id}") public Result findOne(@PathVariable Integer id) { return Result.success(arriveschoolService.getById(id)); } @GetMapping("/page") public Result findPage(@RequestParam(defaultValue = "") String name, @RequestParam Integer userid, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { QueryWrapper<Arriveschool> queryWrapper = new QueryWrapper<>(); queryWrapper.orderByDesc("id"); if (!"".equals(name)) { queryWrapper.like("name", name); } if(userid != -1){ queryWrapper.eq("userid",userid); } return Result.success(arriveschoolService.page(new Page<>(pageNum, pageSize), queryWrapper)); } @GetMapping("/byTeacherPage") public Result findByTeacherPage(@RequestParam(defaultValue = "") String name, @RequestParam Integer userid, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { QueryWrapper<Arriveschool> queryWrapper = new QueryWrapper<>(); queryWrapper.orderByDesc("id"); if (!"".equals(name)) { queryWrapper.like("name", name); } User byId = userService.getById(userid); queryWrapper.eq("classid",byId.getClassid()); return Result.success(arriveschoolService.page(new Page<>(pageNum, pageSize), queryWrapper)); } @GetMapping("/agree") public Result agree(@RequestParam Integer id) { QueryWrapper<Arriveschool> queryWrapper = new QueryWrapper<>(); Arriveschool byId = arriveschoolService.getById(id); if(byId != null){ byId.setStatus("审核通过"); arriveschoolService.updateById(byId); return Result.success("审核通过"); }else{ return Result.error("400","不存在数据,无法审核"); } } @GetMapping("/reject") public Result reject(@RequestParam Integer id) { QueryWrapper<Arriveschool> queryWrapper = new QueryWrapper<>(); Arriveschool byId = arriveschoolService.getById(id); if(byId != null){ byId.setStatus("审核拒绝"); arriveschoolService.updateById(byId); return Result.success("审核拒绝"); }else{ return Result.error("400","不存在数据,无法审核"); } } /** * 导出接口 */ @GetMapping("/export") public void export(HttpServletResponse response) throws Exception { // 从数据库查询出所有的数据 List<Arriveschool> list = arriveschoolService.list(); // 在内存操作,写出到浏览器 ExcelWriter writer = ExcelUtil.getWriter(true); // 一次性写出list内的对象到excel,使用默认样式,强制输出标题 writer.write(list, true); // 设置浏览器响应的格式 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); String fileName = URLEncoder.encode("Arriveschool信息表", "UTF-8"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx"); ServletOutputStream out = response.getOutputStream(); writer.flush(out, true); out.close(); writer.close(); } /** * excel 导入 * @param file * @throws Exception */ @PostMapping("/import") public Result imp(MultipartFile file) throws Exception { InputStream inputStream = file.getInputStream(); ExcelReader reader = ExcelUtil.getReader(inputStream); // 通过 javabean的方式读取Excel内的对象,但是要求表头必须是英文,跟javabean的属性要对应起来 List<Arriveschool> list = reader.readAll(Arriveschool.class); arriveschoolService.saveBatch(list); return Result.success(); } private User getUser() { return TokenUtils.getCurrentUser(); } }
毕业设计|基于SpringBoot+Vue的新生报道(三)https://developer.aliyun.com/article/1423960