私の推奨事項は次のとおりです。パラメーターアプローチをドロップします。
代わりに @RequestBody を使用してください。それははるかにきれいです。@RequestParam は、残りのサービスをすばやくテストするためにサーバーに対して GET リクエストを実行する場合にのみ役立ちます。ある程度複雑なデータを扱っている場合は、最大コンテンツ制限のないサーバーへの POST 要求を使用する方が適切です。
以下は、サーバーにリクエストを送信する方法の例です。注: この場合、バックエンドとして springboot を使用している場合は、コンテンツ タイプ fo を 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);
}
}
UserLoginGwtRpcMessageOverlay はパッチ作業であることに注意してください。これは GwtRpc シリアライズ可能オブジェクトではなく、gwt javascript オブジェクトを拡張するクラスです。
よろしく。