当前位置: 首页 > wzjs >正文

天津网站建设工作室灯饰网站建设哪家便宜

天津网站建设工作室,灯饰网站建设哪家便宜,网站建设价钱,做谷歌外贸较好网站需求 分页查询我的课表 返回: 总条数、总页数、当前页的课表信息的集合 返回的VO(已经封装成统一的LearningLessonsVO) 定义Controller RestController RequestMapping("/lessons") RequiredArgsConstructor public class Lear…

需求

分页查询我的课表

返回:

总条数、总页数、当前页的课表信息的集合

返回的VO(已经封装成统一的LearningLessonsVO)

定义Controller

@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {private final ILearningLessonService lessonService;@GetMapping("/page")public PageDTO<LearningLessonVO> queryMyLesson(PageQuery query) {return lessonService.querMyLesson(query);}
}

2.service实现类

代码逻辑:

(1).因为要查询当前用户下的所有课程分页查询信息,所以首先要拿到用户userId

Long userId = UserContext.getUser();

(2)分页查询并作非空判断,将userId当作条件传给eq,传一个page对象给page方法.

//2.分页查询Page<LearningLesson> page = lambdaQuery().eq(LearningLesson::getUserId, userId).page(query.toMpPage("latest_learn_time", false));List<LearningLesson> records = page.getRecords();if (CollUtils.isEmpty(records)) {return PageDTO.empty(page);}

(3)

先根据从数据库里面查询出来的records拿到每个课程的id。

再根据id调用课程的接口查询每个id对应的课程信息。

判空处理

用stream流的方式将每个课程的id和对应的课程数据放在map中。

//3.查询课程信息//3.1获取课程idSet<Long> Ids = records.stream().map(LearningLesson::getCourseId).collect(Collectors.toSet());//3.2查询课程信息List<CourseSimpleInfoDTO> infoList = courseClient.getSimpleInfoList(Ids);if (CollUtils.isEmpty(infoList)) {throw new BadRequestException("课程信息不存在");}//3.3把课程集合处理成map,key是courseId,value是course本身Map<Long, CourseSimpleInfoDTO> cMap = infoList.stream().collect(Collectors.toMap(CourseSimpleInfoDTO::getId, c -> c));

 (4)

创建一个VO空数组

将po拷贝到VO中

将课程信息set到VO中

最后返回分页查询信息。

//4.封装vo返回List<LearningLessonVO> list = new ArrayList<>(records.size());//循环遍历,吧LearningLesson转变成VOfor (LearningLesson r : records) {//4.1拷贝基础属性到LearningLessonVOLearningLessonVO learningLessonVO = BeanUtils.copyProperties(r, LearningLessonVO.class);//4.2获取课程信息,填充到voCourseSimpleInfoDTO courseSimpleInfoDTO = cMap.get(r.getCourseId());learningLessonVO.setCourseName(courseSimpleInfoDTO.getName());learningLessonVO.setCourseCoverUrl(courseSimpleInfoDTO.getCoverUrl());learningLessonVO.setSections(courseSimpleInfoDTO.getSectionNum());list.add(learningLessonVO);}return PageDTO.of(page, list);

 

 @Overridepublic PageDTO<LearningLessonVO> querMyLesson(PageQuery query) {//1.获取当前登录用户Long userId = UserContext.getUser();//2.分页查询Page<LearningLesson> page = lambdaQuery().eq(LearningLesson::getUserId, userId).page(query.toMpPage("latest_learn_time", false));List<LearningLesson> records = page.getRecords();if (CollUtils.isEmpty(records)) {return PageDTO.empty(page);}//3.查询课程信息//3.1获取课程idSet<Long> Ids = records.stream().map(LearningLesson::getCourseId).collect(Collectors.toSet());//3.2查询课程信息List<CourseSimpleInfoDTO> infoList = courseClient.getSimpleInfoList(Ids);if (CollUtils.isEmpty(infoList)) {throw new BadRequestException("课程信息不存在");}//3.3把课程集合处理成map,key是courseId,value是course本身Map<Long, CourseSimpleInfoDTO> cMap = infoList.stream().collect(Collectors.toMap(CourseSimpleInfoDTO::getId, c -> c));//4.封装vo返回List<LearningLessonVO> list = new ArrayList<>(records.size());//循环遍历,吧LearningLesson转变成VOfor (LearningLesson r : records) {//4.1拷贝基础属性到LearningLessonVOLearningLessonVO learningLessonVO = BeanUtils.copyProperties(r, LearningLessonVO.class);//4.2获取课程信息,填充到voCourseSimpleInfoDTO courseSimpleInfoDTO = cMap.get(r.getCourseId());learningLessonVO.setCourseName(courseSimpleInfoDTO.getName());learningLessonVO.setCourseCoverUrl(courseSimpleInfoDTO.getCoverUrl());learningLessonVO.setSections(courseSimpleInfoDTO.getSectionNum());list.add(learningLessonVO);}return PageDTO.of(page, list);}

 

http://www.dtcms.com/wzjs/822029.html

相关文章:

  • 制作好的网站必须申请建站公司专业定制
  • 织梦网站栏目大鹏网站建设建站好不好
  • 企业内部门户网站建设wordpress如何上传文件大小
  • 建筑设计网站制作wordpress如何添加首页
  • 南宁网站制作专业wordpress advanced
  • 微小店网站建设用途品牌网站建设有哪些功能
  • 做网站付钱方式企业创建网站
  • 网站点击量统计河南郑州暴雨
  • 网站类型分类常德网站建设全域云
  • fireworks学习网站北京高端网站开发公司
  • 网站模板系统平台和自建网站服务提供者
  • 建设网站的市场背景蜜雪冰城网络营销推广方案
  • 自己的服务器做网站建设部网站官网
  • wordpress 页面内链遵义seo网络优化招聘
  • 国内各大网站php学校网站系统
  • 南京外贸网站建设城北区建设局网站
  • 如何做网上水果网站系统群晖 wordpress 端口 转发
  • 网站定制设计网页价格多少钱给孩子做衣服的网站
  • 数据统计网站电子商务网站建设参考文献书籍
  • 帮网站做推广赚钱吗医疗网站建设代理商
  • 服装网站建设项目规划天河区建网站
  • 石碣镇网站仿做网页qq登录保护不再开启入口
  • 新网站建设市场深圳网站备案时间
  • 做网站公司找哪家公司租号网站开发成本
  • 网站费用明细朋友圈信息流广告投放价格
  • 免费企业网站模板成都高投建设开发有限公司网站
  • 高端网站建设公司排行网站建设与管理课程总结
  • 单纯做seo能否提升网站流量建设银行wap网站
  • 沈阳市城乡建设局网站设计师的职责
  • 公众号做视频网站wordpress文件wordpress