如何在gluon javafx应用程序中处理异步API调用(How to handle a async API call in gluon javafx Application)
如何使用gluon移动应用程序登录REST API服务器。 我试过能够调用的HttpClient。
How to login with a REST API server from gluon mobile application. I have tried HttpClient which does able to call .
最满意答案
要访问REST API,您可以使用RestClient。
import com.gluonhq.connect.provider.RestClient; RestClient restClient = RestClient.create() .host("http://myhost.com") .path("restservice/login") .queryParam("username","myname") .queryParam("password","myencodedpassword") .method("GET"); GluonObservableObject<User> sample = DataProvider.retrieveObject(restClient.createObjectDataReader(User.class));然后,要处理结果,可以使用stateProperty
sample.stateProperty().addListener((obv,ov,nv)->{ if(nv.equals(ConnectState.SUCCEEDED)){ User loggedInUser = sample.get(); } });你也可以使用initializedProperty。
RestClient JavaDoc
To access a REST API you can use RestClient.
import com.gluonhq.connect.provider.RestClient; RestClient restClient = RestClient.create() .host("http://myhost.com") .path("restservice/login") .queryParam("username","myname") .queryParam("password","myencodedpassword") .method("GET"); GluonObservableObject<User> sample = DataProvider.retrieveObject(restClient.createObjectDataReader(User.class));To then handle the result you can use the stateProperty
sample.stateProperty().addListener((obv,ov,nv)->{ if(nv.equals(ConnectState.SUCCEEDED)){ User loggedInUser = sample.get(); } });you can use initializedProperty as well.
RestClient JavaDoc
更多推荐
发布评论