阅读背景:

简单的分页查询的实现接口_布偶猫葵葵的博客_分页查询接口

来源:互联网 
package com.leyou.controller;

import com.leyou.PageResult;
import com.leyou.service.BrandService;
import com.pojo.Brand;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("brand")
public class BrandController {

    @Autowired
    private BrandService brandService;
    @GetMapping("page")
    public ResponseEntity<PageResult<Brand>> queryBrand(@RequestParam(value ="page",required = false,defaultValue = "1")int page
    ,@RequestParam(value ="rows",defaultValue = "5",required = false)int rows,
     @RequestParam(value = "sortBy",required = false)String sortBy,
     @RequestParam(value = "desc",required = false) boolean desc,
     @RequestParam(value = "key",required = false) String key
    ){

     //使用service来进行分页查询
    PageResult<Brand>  list=  this.brandService.queryBrandByPage(page,rows,sortBy,desc,key);

    //得到查询的结果进行判断再返回
        if(list==null){
            //如果查询结果是空的话,则可以返回404
         return ResponseEntity.notFound().build();
        }

        return ResponseEntity.ok(list);



    }
}package com.leyou.controller;

import com.leyou



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: