标签:ring style 方法 数据 query auto color span 类对象
使用EasyExcel操作excel https://www.yuque.com/easyexcel/doc/easyexcel
返回指定json格式数据
1)添加课程分类
获取上传过来的excel文件,读取里面的内容,存入数据库
当不需要spring管理的类(如Listern等)调用注入到spring的类的方法时,不能直接使用@Autowired等注解得到,可以通过添加属性和对应的构造方法来获取类对象
2)获取课程分类信息,以指定json格式数据返回{id:xx, title:xx, children:{id:xx, title:xx}}
根据返回的json数据格式创建VO类,封装数据并返回
查询多级分类:分别查出各级分类数据,嵌套循环遍历相关数据
/** * 课程一级分类 */ @Data public class OneSubject { private String id; private String title; private List<TwoSubject> children = new ArrayList<>(); }
/** * 课程二级分类 */ @Data public class TwoSubject { private String id; private String title; }
public List<OneSubject> getAllSubject() { // 获取一级分类数据 QueryWrapper<EduSubject> wrapper = new QueryWrapper<>(); wrapper.eq("parent_id", "0"); List<EduSubject> oneSubjects = baseMapper.selectList(wrapper); // 获取二级分类数据 QueryWrapper<EduSubject> wrapper2 = new QueryWrapper<>(); wrapper2.ne("parent_id", "0"); List<EduSubject> twoSubjects = baseMapper.selectList(wrapper2); //封装一级分类数据(二级分类) List<OneSubject> list = new ArrayList<>(); for (EduSubject eduSubject1 : oneSubjects){ OneSubject oneSubject = new OneSubject(); BeanUtils.copyProperties(eduSubject1,oneSubject); List<TwoSubject> children = new ArrayList<>(); for (EduSubject eduSubject2 : twoSubjects){ if(eduSubject2.getParentId().equals(eduSubject1.getId())){ TwoSubject twoSubject = new TwoSubject(); BeanUtils.copyProperties(eduSubject2, twoSubject); children.add(twoSubject); } } oneSubject.setChildren(children); list.add(oneSubject); } return list; }
标签:ring style 方法 数据 query auto color span 类对象
原文地址:https://www.cnblogs.com/pikachu511/p/14527495.html