Đề xuất của tôi là: Thả phương pháp tham số.
Sử dụng @RequestBody thay thế. Nó sạch hơn nhiều. @RequestParam chỉ hữu ích nếu bạn muốn thực hiện yêu cầu GET đến máy chủ để nhanh chóng kiểm tra các dịch vụ còn lại. Nếu bạn đang xử lý dữ liệu ở bất kỳ mức độ phức tạp nào, bạn nên sử dụng các yêu cầu POST cho máy chủ không có giới hạn nội dung tối đa.
Dưới đây là ví dụ về cách bơm yêu cầu đến máy chủ. LƯU Ý: trong trường hợp này, nếu bạn đang sử dụng springboot làm phần phụ trợ, bạn sẽ phải thao tác kiểu nội dung fo là application/json.
private void invokeRestService() {
try {
// (a) prepare the JSON request to the server
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, JSON_URL);
// Make content type compatible with expetations from SpringBoot
// rest web service
builder.setHeader("Content-Type", "application/json;charset=UTF-8");
// (b) prepare the request object
UserLoginGwtRpcMessageOverlay jsonRequest = UserLoginGwtRpcMessageOverlay.create();
jsonRequest.setUserName("John777");
jsonRequest.setHashedPassword("lalal");
String jsonRequestStr = JsonUtils.stringify(jsonRequest);
// (c) send an HTTP Json request
Request request = builder.sendRequest(jsonRequestStr, new RequestCallback() {
// (i) callback handler when there is an error
public void onError(Request request, Throwable exception) {
LOGGER.log(Level.SEVERE, "Couldn't retrieve JSON", exception);
}
// (ii) callback result on success
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
UserLoginGwtRpcMessageOverlay responseOverlay = JsonUtils
.<UserLoginGwtRpcMessageOverlay>safeEval(response.getText());
LOGGER.info("responseOverlay: " + responseOverlay.getUserName());
} else {
LOGGER.log(Level.SEVERE, "Couldn't retrieve JSON (" + response.getStatusText() + ")");
}
}
});
} catch (RequestException e) {
LOGGER.log(Level.SEVERE, "Couldn't execute request ", e);
}
}
Lưu ý UserLoginGwtRpcMessageOverlay là một bản vá hoạt động. Đây không phải là một đối tượng serializable GwtRpc, nó là một lớp mở rộng đối tượng javascript gwt.
Trân trọng.
Cảm ơn! Servlet chấp nhận của tôi đã không làm việc mà không .... không bao giờ có thể nghĩ về điều đó! Cảm ơn! – Lenz
Vui vì tôi có thể giúp! – z00bs