毕业设计|基于SpringBoot+Vue的新生报道(二)https://developer.aliyun.com/article/1423959
4.2 ClassesController
@RestController @RequestMapping("/classes") public class ClassesController { @Resource private IClassesService classesService; @Resource IUserService userService; private final String now = DateUtil.now(); // 新增或者更新 @PostMapping public Result save(@RequestBody Classes classes) { if (classes.getId() == null) { //classes.setTime(DateUtil.now()); //classes.setUser(TokenUtils.getCurrentUser().getNickname()); //classes.setUserid(TokenUtils.getCurrentUser().getId()); } classesService.saveOrUpdate(classes); return Result.success(); } @DeleteMapping("/{id}") public Result delete(@PathVariable Integer id) { classesService.removeById(id); return Result.success(); } @PostMapping("/del/batch") public Result deleteBatch(@RequestBody List<Integer> ids) { classesService.removeByIds(ids); return Result.success(); } @GetMapping public Result findAll() { return Result.success(classesService.list()); } @GetMapping("/{id}") public Result findOne(@PathVariable Integer id) { return Result.success(classesService.getById(id)); } @GetMapping("/page") public Result findPage(@RequestParam(defaultValue = "") String name, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { QueryWrapper<Classes> queryWrapper = new QueryWrapper<>(); queryWrapper.orderByDesc("id"); if (!"".equals(name)) { queryWrapper.like("name", name); } // User currentUser = TokenUtils.getCurrentUser(); // if (currentUser.getRole().equals("ROLE_USER")) { // queryWrapper.eq("userid", currentUser.getId()); // } return Result.success(classesService.page(new Page<>(pageNum, pageSize), queryWrapper)); } /** * 导出接口 */ @GetMapping("/export") public void export(HttpServletResponse response) throws Exception { // 从数据库查询出所有的数据 List<Classes> list = classesService.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("Classes信息表", "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<Classes> list = reader.readAll(Classes.class); classesService.saveBatch(list); return Result.success(); } private User getUser() { return TokenUtils.getCurrentUser(); } }
五,相关作品展示
基于Java开发、Python开发、PHP开发、C#开发等相关语言开发的实战项目
基于Nodejs、Vue等前端技术开发的前端实战项目
基于微信小程序和安卓APP应用开发的相关作品
基于51单片机等嵌入式物联网开发应用
基于各类算法实现的AI智能应用
基于大数据实现的各类数据管理和推荐系统