简体   繁体   English

是否可以在Java Swing应用程序中使用REST或Web api

[英]Is it possible to use a REST or web api in a java Swing application

I have a Swing application that is done except for the web api part. 我有一个Swing应用程序,除了web api部分。 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. 他们有一个REST api,但是当我看到在java中使用REST api的例子时,他们都使用了一个java web应用程序,我找不到任何桌面swing应用程序。 So is it still possible to do so? 那么它仍然可以这样做吗?

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/

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. 这应该返回一个Response类型的对象。 For other HTTP operations supported by RestTemplate see the Spring documentation . 对于RestTemplate支持的其他HTTP操作,请参阅Spring文档

You can grep this example: Creating RESTful Service Clients in NetBeans Modules. 您可以grep 这个示例:在NetBeans模块中创建RESTful服务客户端。 The example shows how to create a twitter java-swing based desktop client with OAuth support (SWING). 该示例显示了如何使用OAuth支持(SWING)创建基于twitter java-swing的桌面客户端。

Also you can grep this video tutorial for eclipse platform (SWT) 你也可以看一下 eclipse平台(SWT)的视频教程

Here is a JavaFX example for RestFULL client 这是 RestFULL客户端的JavaFX示例

There is very good example of rest desktop client in RESTful Java Web Services by Jose Sandoval. Jose Sandoval在RESTful Java Web服务中有非常好的休眠桌面客户端示例。 Try it on google/books 在谷歌/书籍上试试吧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM