使用球衣访问数据库 RESTful API

database access using jersey RESTful API

如何使用 jersey RESTful JAX-RS api 访问数据库?? 这是 hello.java 我的球衣服务器端

import javax.ws.rs.GET;  
import javax.ws.rs.Path;  
import javax.ws.rs.Produces;  
import javax.ws.rs.core.MediaType;  
@Path("/hello")  
public class Hello 
{
    // This method is called if HTML and XML is not requested  
      @GET  
      @Produces(MediaType.TEXT_PLAIN)  
      public String sayPlainTextHello() 
      {  
          return "Hello Jersey Plain";  
      }  
      // This method is called if XML is requested  
      @GET  
      @Produces(MediaType.TEXT_XML)  
      public String sayXMLHello() 
      {  
          return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";  
      }  

      // This method is called if HTML is requested  
      @GET  
      @Produces(MediaType.TEXT_HTML)  
      public String sayHtmlHello() 
      {  
          return "<html> " + "<title>" + "Hello Jersey" + "</title>"  
            + "<body><h1>" + "Hello Jersey HTML" + "</h1></body>" + "</html> ";  
      }  

}

现在,当我的客户端调用此 url 时,我将我的服务器端代码 return 联系人详细信息(xml 格式)存储在我的数据库中。

泽西岛仅在功能上提供休息服务。要访问数据库,您需要使用 jdbc 或作为另一个抽象 jpa。看看 hibernate for jpa。

如果您查看像 Hibernate 这样的 specification. So to acces a database you should probebely need to use JPA 实现,REST 是一个访问层,因为您需要一个取决于数据库供应商的实现。