DELETE方法支持jsonBody

This commit is contained in:
TS-QD1 2023-06-13 18:24:33 +08:00
parent 6f0f123b09
commit fb48afc6ae
2 changed files with 24 additions and 1 deletions

View File

@ -79,6 +79,8 @@ public class RestRemoteHandler implements InvocationHandler {
requestMethod = RequestMethod.DELETE;
RemoteDeleteMethod deleteMethod = method.getAnnotation(RemoteDeleteMethod.class);
uri = deleteMethod.value();
// 判断json
requestBody = getRequestBody(method.getParameters(), args);
} else if (method.isAnnotationPresent(RemotePostMethod.class)) {
// POST请求
requestMethod = RequestMethod.POST;

View File

@ -70,7 +70,11 @@ public class RestRemoteRequest {
if (RequestMethod.GET.equals(requestMethod)) {
result = get(remoteUri, headers);
} else if (RequestMethod.DELETE.equals(requestMethod)) {
result = delete(remoteUri, headers);
if (jsonBody != null) {
result = delete(remoteUri, headers, jsonBody);
} else {
result = delete(remoteUri, headers);
}
} else if (RequestMethod.POST.equals(requestMethod)) {
// form表单优先
if (!fileVariableParams.isEmpty() || !fileInputVariableParams.isEmpty() || !formVariableParams.isEmpty()) {
@ -121,6 +125,23 @@ public class RestRemoteRequest {
}
}
/**
* DELETE请求
*
* @param remoteUri
* @param headers
* @return
*/
public String delete(String remoteUri, Map<String, String> headers, Object jsonBody) {
try {
HttpEntity<String> httpEntity = getHttpEntity(headers, null, null, null, jsonBody);
ResponseEntity<String> responseEntity = getRestTemplate(remoteUri).exchange(remoteUri, HttpMethod.DELETE, httpEntity, String.class);
return getStringResponse(responseEntity);
} catch (Exception e) {
return getErrorResponse(e);
}
}
/**
* POST请求
*