美文网首页
RESTful Service use comment

RESTful Service use comment

作者: 并肩走天涯 | 来源:发表于2014-12-11 17:52 被阅读54次

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

持续更新...

相关文章

网友评论

      本文标题:RESTful Service use comment

      本文链接:https://www.haomeiwen.com/subject/xmbntttx.html