分页查询设备

This commit is contained in:
2025-06-28 17:18:05 +08:00
parent 1d286634c0
commit f9f5569504
22 changed files with 2078 additions and 30 deletions

View File

@ -93,6 +93,12 @@
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>3.5.12</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -0,0 +1,24 @@
package com.fuyuanshen.common.core.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* 分页结果封装类
* @author Zheng Jie
* @date 2018-11-23
* @param <T>
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> implements Serializable {
private List<T> content;
private long totalElements;
}

View File

@ -0,0 +1,64 @@
package com.fuyuanshen.common.core.domain;
import lombok.Data;
/**
* @Description: 返回体
* @Author: WY
* @Date: 2025/6/2
**/
@Data
public class ResponseVO<T> {
private Integer code; // 成功:0 失败:-1
private String msg;
private T data;
public ResponseVO(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public ResponseVO(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
// 静态方法,用于创建成功的响应
public static <T> ResponseVO<T> success() {
return new ResponseVO<>(0, "操作成功", null);
}
public static <T> ResponseVO<T> success(T data) {
return new ResponseVO<>(0, "操作成功", data);
}
public static <T> ResponseVO<T> success(String msg, T data) {
return new ResponseVO<>(0, msg, data);
}
// 静态方法,用于创建失败的响应
public static <T> ResponseVO<T> fail(String msg) {
return new ResponseVO<>(-1, msg, null);
}
public static <T> ResponseVO<T> fail(String msg, T data) {
return new ResponseVO<>(-1, msg, data);
}
// 链式方法 - 添加泛型支持
public <R> ResponseVO<R> withData(R data) {
return new ResponseVO<>(this.code, this.msg, data);
}
public ResponseVO<T> withMsg(String msg) {
this.msg = msg;
return this;
}
public ResponseVO<T> withCode(Integer code) {
this.code = code;
return this;
}
}

View File

@ -0,0 +1,73 @@
/*
* Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fuyuanshen.common.core.utils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fuyuanshen.common.core.domain.PageResult;
import java.util.Collections;
import java.util.List;
/**
* 分页工具
* @author Zheng Jie
* @date 2018-12-10
*/
public class PageUtil extends cn.hutool.core.util.PageUtil {
/**
* List 分页
*/
public static <T> List<T> paging(int page, int size , List<T> list) {
int fromIndex = page * size;
int toIndex = page * size + size;
if(fromIndex > list.size()){
return Collections.emptyList();
} else if(toIndex >= list.size()) {
return list.subList(fromIndex,list.size());
} else {
return list.subList(fromIndex,toIndex);
}
}
/**
* Page 数据处理
*/
public static <T> PageResult<T> toPage(IPage<T> page) {
return new PageResult<>(page.getRecords(), page.getTotal());
}
/**
* 自定义分页
*/
public static <T> PageResult<T> toPage(List<T> list) {
return new PageResult<>(list, list.size());
}
/**
* 返回空数据
*/
public static <T> PageResult<T> noData () {
return new PageResult<>(null, 0);
}
/**
* 自定义分页
*/
public static <T> PageResult<T> toPage(List<T> list, long totalElements) {
return new PageResult<>(list, totalElements);
}
}