分类分页查询
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.sky.controller.category;
|
||||
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.CategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@Api(tags = "分类相关接口")
|
||||
@RequestMapping("/admin/category")
|
||||
@Slf4j
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 分类分页查询
|
||||
* @param categoryPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分类分页查询")
|
||||
public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
|
||||
log.info("分类分页查询: {}",categoryPageQueryDTO);
|
||||
PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
12
sky-server/src/main/java/com/sky/mapper/CategoryMapper.java
Normal file
12
sky-server/src/main/java/com/sky/mapper/CategoryMapper.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface CategoryMapper {
|
||||
|
||||
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface CategoryService {
|
||||
/**
|
||||
* 分类分页查询
|
||||
* @param categoryPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.mapper.CategoryMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
/**
|
||||
* 分类分页查询
|
||||
* @param categoryPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
|
||||
//设置分页
|
||||
PageHelper.startPage(categoryPageQueryDTO.getPage(), categoryPageQueryDTO.getPageSize());
|
||||
|
||||
Page<Category> page = categoryMapper.pageQuery(categoryPageQueryDTO);
|
||||
|
||||
long total = page.getTotal();
|
||||
List<Category> result = page.getResult();
|
||||
|
||||
return new PageResult(total,result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user