RESTful Service use comment

Java RESTful

  • 注解

    • @ApplicationPath
    • @Path // 聲明資源路徑 @Path("/book") or @Path("/{bookId: [0-9]*}")
      • @PathParam("bookId") <- [PUT POST DELETE]
      • @QueryParam("ip") // query param <- [GET]
    • @Consumes 標識輸入實體的類型
      • @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
    • @Produces 標識返回實體的類型
      • @Produces(MediaType.TEXT_PLAIN) // 傳輸格式是字符串類型 text/plain
      • @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    • MediaType

            <dependency>
                <groupId>org.glassfish.jersey.media</groupId>
                <artifactId>jersey-media-moxy</artifactId>
            </dependency>
      
    • @PUT // http protocol put method
    • @POST // http protocol post method
    • @DELETE // http protocol delete method
    • @GET // http protocol get method
    • Jersey 內部 JAXB 處理 java pojo class 和 xml 格式的信息、json 格式的信息映射:
      • XML
        • @XmlRootElement(name= "book") // root node
        • @XmlElement(name= "book")
        • @XmlAttribute(name= "status") // node attribute
        • @XmlElementWrapper
      • JSON

持續更新...

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容