实现 Java REST Web 服务的最简单框架 [已关闭]
2022-09-01 12:50:37
						在Java中实现客户端和服务器REST框架的最佳框架是什么?我一直在努力寻找易于使用的解决方案。
更新:泽西岛和Restlet似乎都是不错的选择。我们可能会使用 Restlet,但我们会尝试两者。
在Java中实现客户端和服务器REST框架的最佳框架是什么?我一直在努力寻找易于使用的解决方案。
更新:泽西岛和Restlet似乎都是不错的选择。我们可能会使用 Restlet,但我们会尝试两者。
球衣对两者来说都很容易。要编写 Web 服务,请使用注释:
@Path("/helloworld")
public class HelloWorldResource {
    // The Java method will process HTTP GET requests
    @GET
    // The Java method will produce content identified by the MIME Media
    // type "text/plain"
    @Produces("text/plain")
    public String helloWorld() {
        // Return some cliched textual content
        return "Hello World";
    }
}
对于客户端:
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/helloworld");
String s = webResource.get(String.class);
System.out.println(s); // prints Hello World
Restlet 听起来应该提供你想要的东西: