spring - 从 gwt 调用 Spring MicroService
问题描述
我有一个需要调用 Spring Boot 微服务的 GWT 客户端。我认为它可以类似于调用一个休息网络服务,但有没有更好的方法来做到这一点?
解决方案
您可能可以使用RequestBuilder
从 GWT 应用程序的客户端调用您的 API:
import com.google.gwt.http.client.RequestBuilder;
// ....
try {
new RequestBuilder(
RequestBuilder.GET, // GET, POST, etc.
url // url of your microservice endpoint
).sendRequest(null, new RequestCallback() { // replace null with your req body if needed
@Override
public void onResponseReceived(Request req, Response resp) {
// Parse resp.getText() which is hopefully a JSON string
}
@Override
public void onError(Request res, Throwable throwable) {
// handle errors
}
});
} catch (RequestException e) {
// log, rethrow... the usual
}
推荐阅读
- sql-server - 在查询中主要插入时查询完成并出现错误
- python - GLTF 中的平移和缩放
- laravel - 在从 docker-compose.yml 完成 docker build 后触发在容器内执行自定义 shell 脚本以运行迁移和 db:seed
- php - 按标签或类别搜索产品不起作用
- c# - 在 C# 中清除静态列表
- r - 错误:替换有 x 行,数据有 y
- qt - QML 我如何将默认选项设置为组合框的空值?
- abap - 删除一列包含字符“+”的内部表格行
- angular - 无法通过 2 个级别传递 ngModel
- android - 通过使用自定义地图提取将一个可观察的对象溢出到两个