3 changed files with 81 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||
|
package com.kms.yxgh.base; |
||||
|
|
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import org.springframework.core.MethodParameter; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.http.converter.HttpMessageConverter; |
||||
|
import org.springframework.http.server.ServerHttpRequest; |
||||
|
import org.springframework.http.server.ServerHttpResponse; |
||||
|
import org.springframework.web.bind.annotation.ControllerAdvice; |
||||
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; |
||||
|
|
||||
|
@ControllerAdvice |
||||
|
public class GlobalSyResponseHandler implements ResponseBodyAdvice<Object> { |
||||
|
|
||||
|
@Override |
||||
|
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { |
||||
|
if (body instanceof IPage) { |
||||
|
return SyPage.of((IPage<?>) body); |
||||
|
} else { |
||||
|
return body; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package com.kms.yxgh.base; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
|
||||
|
/** |
||||
|
* @ClassName: ISyPage |
||||
|
* @Description: TODO |
||||
|
* @Date: 2024/3/19 下午1:59 |
||||
|
* * |
||||
|
* @author: hxh |
||||
|
* @version: 1.0 |
||||
|
*/ |
||||
|
|
||||
|
public interface ISyPage<T> extends IPage<T> { |
||||
|
|
||||
|
default Integer getCode() { |
||||
|
return 200; |
||||
|
} |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
package com.kms.yxgh.base; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
/** |
||||
|
* @ClassName: SyPage |
||||
|
* @Description: TODO |
||||
|
* @Date: 2024/3/19 下午2:01 |
||||
|
* * |
||||
|
* @author: hxh |
||||
|
* @version: 1.0 |
||||
|
*/ |
||||
|
|
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class SyPage<T> extends Page<T> implements ISyPage<T> { |
||||
|
|
||||
|
public static <R> ISyPage<R> of(IPage<R> page) { |
||||
|
SyPage<R> syPage = new SyPage<>(); |
||||
|
syPage.setCurrent(page.getCurrent()); |
||||
|
syPage.setSize(page.getSize()); |
||||
|
syPage.setTotal(page.getTotal()); |
||||
|
syPage.setRecords(page.getRecords()); |
||||
|
syPage.setPages(page.getPages()); |
||||
|
return syPage; |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue