【问题标题】:How to handle a async API call in gluon javafx Application如何在 gluon javafx 应用程序中处理异步 API 调用
【发布时间】:2016-08-06 13:50:32
【问题描述】:

如何从 gluon 移动应用程序使用 REST API 服务器登录。我试过 HttpClient 确实可以调用。

【问题讨论】:

    标签: rest javafx gluon gluon-mobile gluon-desktop


    【解决方案1】:

    要访问 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

    【讨论】:

    • 这里的 user.class 是什么?
    • User.class 是一个 POJO。您必须提供此内容以匹配返回的对象。 Retreive Object
    • 我将如何使用ProgressIndicator 进行后台进度。
    • 我没有为 DataProvider 找到任何提供进度值的东西。使用不确定进度指示器。
    猜你喜欢
    • 1970-01-01
    • 2018-08-05
    • 2021-08-28
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    相关资源
    最近更新 更多