grails - 从微服务中获取数据以存放在 grails 中
问题描述
我有一个休息和一个微服务。在微服务中,我有一个表格,我希望将该表格数据提取到休息,我在休息演示控制器中编写了以下方式。
def result = restBuilder().post("http://localhost:2222/api/microservice/fetchData"){
header 'authorization', 'fdgtertddfgfdgfffffff'
accept("application/json")
contentType("application/json")
json "{'empId':1,'ename':'test1'}"
}
但它会引发错误“没有方法签名:demoController.restBuilder() 适用于参数类型:() 值:[]”。我应该如何从微服务中获取数据以进行休息?
解决方案
您正在调用一个名为的方法restBuilder()
,但该方法不存在。如果您希望它起作用,您将需要实现该方法并让它返回可以处理对post(String, Closure)
.
您可能打算使用RestBuilder
该类。具体细节取决于您使用的 Grails 版本,但您可能想要的是这样的......
RestBuilder restBuilder = new RestBuilder()
restBuilder.post('http://localhost:2222/api/microservice/fetchData'){
header 'authorization', 'fdgtertddfgfdgfffffff'
accept 'application/json'
json {
empId = 1
name = 'test1'
}
}
您可能需要grails-datastore-rest-client
在build.gradle
.
compile "org.grails:grails-datastore-rest-client"
我希望这会有所帮助。
推荐阅读
- android - 如何使 [RecyclerView] 的几个最后可见项目变灰?
- python - TypeError:输入类型不支持 ufunc 'invert'
- jquery - 如何计算 Laravel onchange 中日期选择器之间的 no_of_days
- typescript - 按具有多值的其他对象过滤对象
- bazel - Starlark / Bazel 中有 splat 操作员吗?
- azure - Azure SQL 数据仓库 Polybase 查询到 Azure Data Lake Gen 2 返回零行
- javascript - Vue.JS:单击 CLICK-ME 时,我只想更改背景颜色这个 CHANGE-COLOR
- python - 何时在 Python 中使用 io.BytesIO() 来修改字符串
- python-3.x - re.compile 中的两种模式
- java - Java HTML XPath 选择器