mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-15 01:01:36 +08:00
优化:优化模型类命名(为数据模型类添加 DO 后缀),并优化所有模型相关变量命名
This commit is contained in:
@@ -29,7 +29,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageInfo;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||
import top.charles7c.cnadmin.common.model.vo.R;
|
||||
|
||||
/**
|
||||
@@ -67,9 +67,9 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D,
|
||||
*/
|
||||
@Operation(summary = "分页查询列表")
|
||||
@GetMapping
|
||||
protected R<PageInfo<V>> page(@Validated Q query, @Validated PageQuery pageQuery) {
|
||||
PageInfo<V> pageInfo = baseService.page(query, pageQuery);
|
||||
return R.ok(pageInfo);
|
||||
protected R<PageDataVO<V>> page(@Validated Q query, @Validated PageQuery pageQuery) {
|
||||
PageDataVO<V> pageDataVO = baseService.page(query, pageQuery);
|
||||
return R.ok(pageDataVO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,7 +20,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageInfo;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||
|
||||
/**
|
||||
* 业务接口基类
|
||||
@@ -49,8 +49,8 @@ public interface BaseService<V, D, Q, C, U> {
|
||||
* 分页查询条件
|
||||
* @return 分页列表信息
|
||||
*/
|
||||
default PageInfo<V> page(Q query, PageQuery pageQuery) {
|
||||
return new PageInfo<>();
|
||||
default PageDataVO<V> page(Q query, PageQuery pageQuery) {
|
||||
return new PageDataVO<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -29,7 +29,7 @@ import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageInfo;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||
import top.charles7c.cnadmin.common.util.helper.QueryHelper;
|
||||
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
||||
|
||||
@@ -53,10 +53,10 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C, U>
|
||||
protected Class<D> detailVoClass = currentDetailVoClass();
|
||||
|
||||
@Override
|
||||
public PageInfo<V> page(Q query, PageQuery pageQuery) {
|
||||
public PageDataVO<V> page(Q query, PageQuery pageQuery) {
|
||||
QueryWrapper<T> queryWrapper = QueryHelper.build(query);
|
||||
IPage<T> page = baseMapper.selectPage(pageQuery.toPage(), queryWrapper);
|
||||
return PageInfo.build(page, voClass);
|
||||
return PageDataVO.build(page, voClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -40,7 +40,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(description = "分页信息")
|
||||
public class PageInfo<V> {
|
||||
public class PageDataVO<V> {
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
@@ -52,7 +52,7 @@ public class PageInfo<V> {
|
||||
* 总记录数
|
||||
*/
|
||||
@Schema(description = "总记录数")
|
||||
private long total;
|
||||
private Long total;
|
||||
|
||||
/**
|
||||
* 基于 MyBatis Plus 分页数据构建分页信息,并将源数据转换为指定类型数据
|
||||
@@ -67,14 +67,14 @@ public class PageInfo<V> {
|
||||
* 目标列表数据类型
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <T, V> PageInfo<V> build(IPage<T> page, Class<V> targetClass) {
|
||||
public static <T, V> PageDataVO<V> build(IPage<T> page, Class<V> targetClass) {
|
||||
if (page == null) {
|
||||
return null;
|
||||
}
|
||||
PageInfo<V> pageInfo = new PageInfo<>();
|
||||
pageInfo.setList(BeanUtil.copyToList(page.getRecords(), targetClass));
|
||||
pageInfo.setTotal(page.getTotal());
|
||||
return pageInfo;
|
||||
PageDataVO<V> pageDataVO = new PageDataVO<>();
|
||||
pageDataVO.setList(BeanUtil.copyToList(page.getRecords(), targetClass));
|
||||
pageDataVO.setTotal(page.getTotal());
|
||||
return pageDataVO;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,14 +86,14 @@ public class PageInfo<V> {
|
||||
* 列表数据类型
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <V> PageInfo<V> build(IPage<V> page) {
|
||||
public static <V> PageDataVO<V> build(IPage<V> page) {
|
||||
if (page == null) {
|
||||
return null;
|
||||
}
|
||||
PageInfo<V> pageInfo = new PageInfo<>();
|
||||
pageInfo.setList(page.getRecords());
|
||||
pageInfo.setTotal(pageInfo.getTotal());
|
||||
return pageInfo;
|
||||
PageDataVO<V> pageDataVO = new PageDataVO<>();
|
||||
pageDataVO.setList(page.getRecords());
|
||||
pageDataVO.setTotal(page.getTotal());
|
||||
return pageDataVO;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,23 +109,23 @@ public class PageInfo<V> {
|
||||
* 列表数据类型
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <V> PageInfo<V> build(int page, int size, List<V> list) {
|
||||
PageInfo<V> pageInfo = new PageInfo<>();
|
||||
public static <V> PageDataVO<V> build(int page, int size, List<V> list) {
|
||||
PageDataVO<V> pageDataVO = new PageDataVO<>();
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return pageInfo;
|
||||
return pageDataVO;
|
||||
}
|
||||
|
||||
pageInfo.setTotal(list.size());
|
||||
pageDataVO.setTotal((long)list.size());
|
||||
// 对列表数据进行分页
|
||||
int fromIndex = (page - 1) * size;
|
||||
int toIndex = page * size + size;
|
||||
if (fromIndex > list.size()) {
|
||||
pageInfo.setList(new ArrayList<>());
|
||||
pageDataVO.setList(new ArrayList<>());
|
||||
} else if (toIndex >= list.size()) {
|
||||
pageInfo.setList(list.subList(fromIndex, list.size()));
|
||||
pageDataVO.setList(list.subList(fromIndex, list.size()));
|
||||
} else {
|
||||
pageInfo.setList(list.subList(fromIndex, toIndex));
|
||||
pageDataVO.setList(list.subList(fromIndex, toIndex));
|
||||
}
|
||||
return pageInfo;
|
||||
return pageDataVO;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user