zoukankan      html  css  js  c++  java
  • 在线教育项目-day13【课程列表后端】

    1.创建一个vo类,用来封装查询的对象

    package com.dm.eduservice.entity.front;
    
    import io.swagger.annotations.ApiModelProperty;
    import lombok.Data;
    
    import java.io.Serializable;
    
    @Data
    public class CourseQueryVo implements Serializable {
        private static final long serialVersionUID = 1L;
    
        @ApiModelProperty(value = "课程名称")
        private String title;
    
        @ApiModelProperty(value = "讲师id")
        private String teacherId;
    
        @ApiModelProperty(value = "一级类别id")
        private String subjectParentId;
    
        @ApiModelProperty(value = "二级类别id")
        private String subjectId;
    
        @ApiModelProperty(value = "销量排序")
        private String buyCountSort;
    
        @ApiModelProperty(value = "最新时间排序")
        private String gmtCreateSort;
    
        @ApiModelProperty(value = "价格排序")
        private String priceSort;
    }

    2.创建一个Controller

    书写我们的查询方法

    @RestController
    @RequestMapping("eduservice/coursefront")
    @CrossOrigin
    public class CourseFrontController {
        @Autowired
        EduCourseService courseService;
        @PostMapping(value = "{page}/{limit}")
        public R pageList(
                @PathVariable Long page,
                @PathVariable Long limit,
                @RequestBody(required = false) CourseQueryVo courseQuery){
            Page<EduCourse> pageParam = new Page<EduCourse>(page, limit);
            Map<String, Object> map = courseService.pageListWeb(pageParam, courseQuery);
            return  R.OK().data(map);
        }
    
    }

    3.书写ServiceImpl里的方法

     @Override
        public Map<String, Object> pageListWeb(Page<EduCourse> pageParam, CourseQueryVo courseQuery) {
            QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
            if (!StringUtils.isEmpty(courseQuery.getSubjectParentId())) {
                queryWrapper.eq("subject_parent_id", courseQuery.getSubjectParentId());
            }
    
            if (!StringUtils.isEmpty(courseQuery.getSubjectId())) {
                queryWrapper.eq("subject_id", courseQuery.getSubjectId());
            }
    
            if (!StringUtils.isEmpty(courseQuery.getBuyCountSort())) {
                queryWrapper.orderByDesc("buy_count");
            }
    
            if (!StringUtils.isEmpty(courseQuery.getGmtCreateSort())) {
                queryWrapper.orderByDesc("gmt_create");
            }
    
            if (!StringUtils.isEmpty(courseQuery.getPriceSort())) {
                queryWrapper.orderByDesc("price");
            }
    
            baseMapper.selectPage(pageParam, queryWrapper);
    
            List<EduCourse> records = pageParam.getRecords();
            long current = pageParam.getCurrent();
            long pages = pageParam.getPages();
            long size = pageParam.getSize();
            long total = pageParam.getTotal();
            boolean hasNext = pageParam.hasNext();
            boolean hasPrevious = pageParam.hasPrevious();
    
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("items", records);
            map.put("current", current);
            map.put("pages", pages);
            map.put("size", size);
            map.put("total", total);
            map.put("hasNext", hasNext);
            map.put("hasPrevious", hasPrevious);
            return map;
        }
  • 相关阅读:
    js 解析 url参数中文的情况
    ++i i++ 的理解
    Linux 下升级python和安装pip
    sipp中的action使用方法
    Linux shell实现阳历转农历
    Linux 终端命令行提示符的艺术PS1进阶
    SQL系列学习(三) 获取Oracle、SqlServer、Access中表名、字段和主键
    SQL系列学习(一) 分页
    自定义服务器控件属性的特性
    JQuery使用$.ajax跨域调用winform托管的WCF服务(原创)
  • 原文地址:https://www.cnblogs.com/dmzna/p/12863149.html
Copyright © 2011-2022 走看看