update BaseMapper.page

This commit is contained in:
Timi
2025-12-03 10:40:50 +08:00
parent 745b3acfef
commit 7aadec7306
4 changed files with 97 additions and 41 deletions

View File

@@ -1,5 +1,7 @@
package com.imyeyu.spring.mapper;
import com.imyeyu.spring.bean.Page;
import com.imyeyu.spring.bean.PageResult;
import com.imyeyu.spring.util.SQLProvider;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
@@ -8,7 +10,6 @@ import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import java.util.List;
import java.util.Map;
/**
* 基本 SQL 映射,子接口可以不实现
@@ -40,26 +41,35 @@ public interface BaseMapper<T, P> {
String PAGE = NOT_DELETE + " LIMIT #{offset}, #{limit}";
/**
* 统计数据量
* 根据 Page 对象查询数据列表
*
* @return 数据量
*/
@SelectProvider(type = SQLProvider.class, method = "count")
long count();
default List<T> list(long offset, int limit) {
return listOrder(offset, limit, null);
}
/**
* 获取部分数据
*
* @param offset 偏移
* @param limit 数据量
* @param page 分页参数
* @return 数据列表
*/
@SelectProvider(type = SQLProvider.class, method = "listOrder")
List<T> listOrder(long offset, int limit, Map<String, OrderType> orderMap);
@SelectProvider(type = SQLProvider.class, method = "listByPage")
List<T> listByPage(Page page);
/**
* 根据 Page 对象统计数据量
*
* @param page 分页参数
* @return 数据量
*/
@SelectProvider(type = SQLProvider.class, method = "countByPage")
long countByPage(Page page);
/**
* 分页查询
*
* @param page 分页参数
* @return 分页结果
*/
default PageResult<T> page(Page page) {
PageResult<T> result = new PageResult<>();
result.setTotal(countByPage(page));
result.setList(listByPage(page));
return result;
}
@SelectProvider(type = SQLProvider.class, method = "listAll")
List<T> listAll();