mybatis-plus查询时---如何按照某个字段进行倒序排列呢?
下文笔者讲述Mybatisp-plus查询时-指定排序字段的方法分享,如下所示
使用 queryWrapper.orderByDesc 方法设置相应的字段 即可实现指定字段排序例:mybatis plus指定字段排序
@ApiOperation(value="分页列表查询", notes="分页列表查询") @GetMapping(value = "/list") public Result<IPage<DietCharts>> queryPageList(DietCharts dietCharts, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) { QueryWrapper<DietCharts> queryWrapper = QueryGenerator.initQueryWrapper(dietCharts, req.getParameterMap()); Page<DietCharts> page = new Page<DietCharts>(pageNo, pageSize); queryWrapper.orderByDesc("create_time"); List<DietCharts> list = dietChartsService.list(queryWrapper); Collections.sort(list, (o1, o2) -> o2.getSignInPoints().compareTo(o1.getSignInPoints())); Page<DietCharts> pageResult = new Page<>(pageNo, pageSize, page.getTotal()); pageResult.setRecords(list); IPage<DietCharts> pageList = pageResult; // IPage<DietCharts> pageList = dietChartsService.selectList(pageNo,pageSize,dietCharts); return Result.OK(pageList); }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。