2025/3/13 21:44:08---修改分页查询
This commit is contained in:
parent
7635080c7d
commit
5da43ea330
@ -33,13 +33,31 @@ public class RequestProcessor {
|
|||||||
return Long.parseLong(idStr);
|
return Long.parseLong(idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从请求体解析分页参数
|
* 从请求体解析分页参数
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> extractPageParams(Exchange exchange) throws Exception {
|
public Map<String, Object> extractPageCountParams(Exchange exchange) throws Exception {
|
||||||
String body = exchange.getIn().getBody(String.class);
|
Object body = exchange.getIn().getBody();
|
||||||
PageRequest pageRequest = objectMapper.readValue(body, PageRequest.class);
|
PageRequest pageRequest = null;
|
||||||
|
if(body instanceof String){
|
||||||
|
String bodyStr = (String) body;
|
||||||
|
LOGGER.info("分页拿到的请求body: {}", bodyStr);
|
||||||
|
pageRequest = objectMapper.readValue(bodyStr, PageRequest.class);
|
||||||
|
// 保存请求对象供后续使用
|
||||||
|
exchange.setProperty("pageRequest", pageRequest);
|
||||||
|
|
||||||
|
}else if(body instanceof Map){
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> bodyMap = (Map<String, Object>) body;
|
||||||
|
LOGGER.info("分页拿到的请求body: {}", bodyMap);
|
||||||
|
pageRequest = objectMapper.convertValue(bodyMap, PageRequest.class);
|
||||||
|
}else{
|
||||||
|
// 处理其他类型或null
|
||||||
|
LOGGER.warn("无法处理的请求体类型: {}", body != null ? body.getClass().getName() : "null");
|
||||||
|
pageRequest = new PageRequest();
|
||||||
|
pageRequest.setPage(1);
|
||||||
|
pageRequest.setSize(10);
|
||||||
|
}
|
||||||
// 保存请求对象供后续使用
|
// 保存请求对象供后续使用
|
||||||
exchange.setProperty("pageRequest", pageRequest);
|
exchange.setProperty("pageRequest", pageRequest);
|
||||||
|
|
||||||
@ -52,13 +70,40 @@ public class RequestProcessor {
|
|||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> extractPageParams(Exchange exchange) throws Exception {
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
PageRequest pageRequest = (PageRequest) exchange.getProperty("pageRequest");
|
||||||
|
if(pageRequest == null){
|
||||||
|
throw new Exception("分页请求对象为空");
|
||||||
|
}
|
||||||
|
params.put("offset", pageRequest.getOffset());
|
||||||
|
params.put("limit", pageRequest.getLimit());
|
||||||
|
params.put("filters", pageRequest.getFilters());
|
||||||
|
params.put("sortField", pageRequest.getSortField());
|
||||||
|
params.put("sortOrder", pageRequest.getSortOrder());
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从请求体解析高级搜索参数
|
* 从请求体解析高级搜索数量参数
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> extractSearchParams(Exchange exchange) throws Exception {
|
public Map<String, Object> extractSearchCountParams(Exchange exchange) throws Exception {
|
||||||
String body = exchange.getIn().getBody(String.class);
|
Object body = exchange.getIn().getBody();
|
||||||
AdvancedSearchRequest searchRequest = objectMapper.readValue(body, AdvancedSearchRequest.class);
|
AdvancedSearchRequest searchRequest = null;
|
||||||
|
if(body instanceof String){
|
||||||
|
String bodyStr = (String) body;
|
||||||
|
LOGGER.info("高级搜索拿到的请求body: {}", bodyStr);
|
||||||
|
searchRequest = objectMapper.readValue(bodyStr, AdvancedSearchRequest.class);
|
||||||
|
}else if(body instanceof Map){
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> bodyMap = (Map<String, Object>) body;
|
||||||
|
LOGGER.info("高级搜索拿到的请求body: {}", bodyMap);
|
||||||
|
searchRequest = objectMapper.convertValue(bodyMap, AdvancedSearchRequest.class);
|
||||||
|
}else{
|
||||||
|
LOGGER.warn("无法处理的请求体类型: {}", body != null ? body.getClass().getName() : "null");
|
||||||
|
searchRequest = new AdvancedSearchRequest();
|
||||||
|
}
|
||||||
|
|
||||||
// 保存请求对象供后续使用
|
// 保存请求对象供后续使用
|
||||||
exchange.setProperty("searchRequest", searchRequest);
|
exchange.setProperty("searchRequest", searchRequest);
|
||||||
@ -73,6 +118,24 @@ public class RequestProcessor {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从请求体解析高级搜索参数
|
||||||
|
*/
|
||||||
|
public Map<String, Object> extractSearchParams(Exchange exchange) throws Exception {
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
AdvancedSearchRequest searchRequest = (AdvancedSearchRequest) exchange.getProperty("searchRequest");
|
||||||
|
if(searchRequest == null){
|
||||||
|
throw new Exception("高级搜索请求对象为空");
|
||||||
|
}
|
||||||
|
params.put("offset", searchRequest.getOffset());
|
||||||
|
params.put("limit", searchRequest.getLimit());
|
||||||
|
params.put("criteria", searchRequest.getCriteria());
|
||||||
|
params.put("sortField", searchRequest.getSortField());
|
||||||
|
params.put("sortOrder", searchRequest.getSortOrder());
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 准备实体创建参数,通用方法
|
* 准备实体创建参数,通用方法
|
||||||
* @param <T> 实体类型
|
* @param <T> 实体类型
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
- bean:
|
- bean:
|
||||||
id: bean-4910
|
id: bean-4910
|
||||||
ref: requestProcessor
|
ref: requestProcessor
|
||||||
method: extractPageParams
|
method: extractPageCountParams
|
||||||
- log:
|
- log:
|
||||||
id: log-ea02
|
id: log-ea02
|
||||||
message: ${body}
|
message: ${body}
|
||||||
@ -82,6 +82,10 @@
|
|||||||
- log:
|
- log:
|
||||||
id: log-21e9
|
id: log-21e9
|
||||||
message: ${body}
|
message: ${body}
|
||||||
|
- bean:
|
||||||
|
id: bean-7ad2
|
||||||
|
ref: requestProcessor
|
||||||
|
method: extractPageParams
|
||||||
- to:
|
- to:
|
||||||
id: to-d904
|
id: to-d904
|
||||||
uri: mybatis
|
uri: mybatis
|
||||||
|
Loading…
x
Reference in New Issue
Block a user