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