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);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 从请求体解析分页参数
|
||||
*/
|
||||
public Map<String, Object> extractPageParams(Exchange exchange) throws Exception {
|
||||
String body = exchange.getIn().getBody(String.class);
|
||||
PageRequest pageRequest = objectMapper.readValue(body, PageRequest.class);
|
||||
public Map<String, Object> extractPageCountParams(Exchange exchange) throws Exception {
|
||||
Object body = exchange.getIn().getBody();
|
||||
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);
|
||||
|
||||
@ -53,12 +71,39 @@ public class RequestProcessor {
|
||||
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 {
|
||||
String body = exchange.getIn().getBody(String.class);
|
||||
AdvancedSearchRequest searchRequest = objectMapper.readValue(body, AdvancedSearchRequest.class);
|
||||
public Map<String, Object> extractSearchCountParams(Exchange exchange) throws Exception {
|
||||
Object body = exchange.getIn().getBody();
|
||||
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);
|
||||
@ -73,6 +118,24 @@ public class RequestProcessor {
|
||||
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> 实体类型
|
||||
|
@ -62,7 +62,7 @@
|
||||
- bean:
|
||||
id: bean-4910
|
||||
ref: requestProcessor
|
||||
method: extractPageParams
|
||||
method: extractPageCountParams
|
||||
- log:
|
||||
id: log-ea02
|
||||
message: ${body}
|
||||
@ -82,6 +82,10 @@
|
||||
- log:
|
||||
id: log-21e9
|
||||
message: ${body}
|
||||
- bean:
|
||||
id: bean-7ad2
|
||||
ref: requestProcessor
|
||||
method: extractPageParams
|
||||
- to:
|
||||
id: to-d904
|
||||
uri: mybatis
|
||||
|
Loading…
x
Reference in New Issue
Block a user