package com.dy.common.webUtil; import com.alibaba.fastjson2.annotation.JSONField; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.util.Map; @Data @ToString @NoArgsConstructor @AllArgsConstructor @Builder @Schema(name = "查询结果基类") public class QueryResultVo { /** * 每页显示的记录数 */ @Schema(description = "每页记录数") public Integer pageSize ; /** * 记录总数 */ @Schema(description = "记录总数") public Long itemTotal ; /** * 当前页 */ @Schema(description = "当前页") public Integer pageCurr ; /** * 总页数 */ @Schema(description = "总页数") public Integer pageTotal ; @Schema(description = "数据") public T obj; /** * 查询开始记录 */ @Schema(hidden = true) @JSONField(serialize = false) public Integer queryStart ; /** * 查询数量 */ @Schema(hidden = true) @JSONField(serialize = false) public Integer queryCount ; public void calculateAndSet(Long itemTotal, Map params) { this.itemTotal = itemTotal ; if(this.itemTotal == null){ this.itemTotal = 0L ; } if(this.itemTotal == 0){ this.pageSize = 10 ; } if(this.pageSize == null || this.pageSize <= 0){ /** * 朱宝民 2024-01-30 修改 * 未传入分页参数时,取全部记录 */ //this.pageSize = 1 ;//供下面作为除数 this.pageSize = 10 ;//供下面作为除数 } pageTotal = (int)Math.ceil((itemTotal==null?0.0D:itemTotal.doubleValue())/pageSize); if (pageTotal == 0) { pageTotal = 1; } if (pageCurr == null || pageCurr < 1) { pageCurr = 1; } if (pageCurr > pageTotal) { pageCurr = pageTotal; } //select * from table_name limit 5 ,10;//从第6行开始,检索10行记录,即:检索记录行 6-15 this.queryStart = (this.pageCurr - 1) * this.pageSize ; this.queryCount = this.pageSize ; if(params != null){ params.put("start", this.queryStart) ; params.put("count", this.queryCount) ; } } }