是否可以在 java Swing 应用程序中使用 REST 或 web api
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25287767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to use a REST or web api in a java Swing application
提问by rasen58
I have a Swing application that is done except for the web api part. They have a REST api, but when I was looking at example of using a REST api in java, they all use a java web application, and I can't find any for a desktop swing application. So is it still possible to do so?
我有一个除了 web api 部分之外的 Swing 应用程序。他们有一个 REST api,但是当我查看在 Java 中使用 REST api 的示例时,他们都使用了一个 Java Web 应用程序,而我找不到任何适用于桌面 Swing 应用程序的应用程序。那么还有可能这样做吗?
回答by Ninad Pingale
Yes. It is possible.
是的。有可能的。
You can Consume (access and read) a REST web service in Swing desktop application.
您可以在 Swing 桌面应用程序中使用(访问和读取)REST Web 服务。
You can achieve it using HTTPClient
.
您可以使用HTTPClient
.
An example - http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-apache-httpclient/
一个例子 - http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-apache-httpclient/
回答by monim
Use Spring RestTemplate an example here.
在此处使用 Spring RestTemplate 示例。
RestTemplate rest = new RestTemplate()
rest.postForObject("http://localhost:8080/WebApp/ServiceName", requestBean, Response.class);
This should return an object of type Response. For other HTTP operations supported by RestTemplate see the Spring documentation.
这应该返回一个响应类型的对象。有关 RestTemplate 支持的其他 HTTP 操作,请参阅Spring 文档。
回答by shcherbak
You can grep thisexample: Creating RESTful Service Clients in NetBeans Modules. The example shows how to create a twitter java-swing based desktop client with OAuth support (SWING).
你可以grep这个例子:创建NetBeans模块中的REST风格的服务客户端。该示例展示了如何创建具有 OAuth 支持 (SWING) 的基于 twitter java-swing 的桌面客户端。
Also you can grep thisvideo tutorial for eclipse platform (SWT)
您也可以为 Eclipse 平台 (SWT) 搜索此视频教程
Here isa JavaFX example for RestFULL client
这是RestFULL 客户端的 JavaFX 示例
There is very good example of rest desktop client in RESTful Java Web Servicesby Jose Sandoval. Try it on google/books
Jose Sandoval在RESTful Java Web 服务中有一个很好的桌面客户端示例。在 google/books 上试试