[英]How to return a class member string in groovy script
我有以下代碼片段
class **ResultToken** {
String token
String expiration
}
// HTTP post request to retrive active token
// Return : ResultToken object
ResultToken getToken(){
ResultToken token
http.request(POST) {
...
response.success = { resp, json ->
token = new ResultToken(token: json["access_token"].toString(),
expiration: json["expires_in"].toString())
}
}
token
}
def tokenValue =getToken().token
return tokenValue
Exception error: groovy.lang.MissingPropertyException: No such property: http for class: Script259 at Script259.getToken(Script259.groovy:21) at Script259.run(Script259.groovy:41)
任何想法?
問候
通過這種方式,您可以定義不返回任何有用的處理程序。
它應該是:
ResultToken getToken(){
ResultToken token
http.request(POST) {
....
response.success = { resp, json ->
token = new ResultToken(token: json.access_token, expiration: json.expires_in)
}
}
token
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.