我正在苦苦思索着我宁静的web服务(Java和Netbeans 8.2)
我的方法如下所示:
@POST @Path("/usedPacking") @Consumes(MediaType.APPLICATION_JSON) public void setUsedPackage( ??? ) { ??? }实际上,我希望收到一条json邮件,如后面的数据:{“PackageID”:“12345”,“Used”:“false”}
我的问题是:我有什么要取代“???” 用?
对于GET方法,它是:
@QueryParam("ID") String input这允许我通过使用输入访问指定为ID的变量。
我迄今发现的一切都没有解决我面临的问题。
I'm struggling with my restful webservice (Java & Netbeans 8.2)
My method looks like:
@POST @Path("/usedPacking") @Consumes(MediaType.APPLICATION_JSON) public void setUsedPackage( ??? ) { ??? }Actually I would like to receive a json-message as post-data like: {"PackageID":"12345","Used":"false"}
My question is: What do I have to replace the "???" with?
For GET-Methods it is:
@QueryParam("ID") String inputWhich allows me to access the variable specified as ID by using input.
Everything I've found so far didn't quite address the problem I face..
最满意答案
对于JAXRS webservice,您可以创建一个注释类,它映射到您的json,例如
import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Package { private String packageID; private Boolean used; // getters and setters here }然后 ??? 将是你的班级
public void setUsedPackage(Package package)当你发布你的json时,你需要将Content-type头指定为application / json
这里有一个我发现可能有帮助的jaxrs教程
http://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/post-example/
For a JAXRS webservice you can create an annotated class that maps to your json e.g.
import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Package { private String packageID; private Boolean used; // getters and setters here }then ??? will be your class
public void setUsedPackage(Package package)When you post your json you'll need to specify the Content-type header as application/json
Here's a jaxrs tutorial I found that may help
http://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/post-example/
如何使用Java访问netbeans中的json Post方法值(How to access json Post method values in netbeans using Java)我正在苦苦思索着我宁静的web服务(Java和Netbeans 8.2)
我的方法如下所示:
@POST @Path("/usedPacking") @Consumes(MediaType.APPLICATION_JSON) public void setUsedPackage( ??? ) { ??? }实际上,我希望收到一条json邮件,如后面的数据:{“PackageID”:“12345”,“Used”:“false”}
我的问题是:我有什么要取代“???” 用?
对于GET方法,它是:
@QueryParam("ID") String input这允许我通过使用输入访问指定为ID的变量。
我迄今发现的一切都没有解决我面临的问题。
I'm struggling with my restful webservice (Java & Netbeans 8.2)
My method looks like:
@POST @Path("/usedPacking") @Consumes(MediaType.APPLICATION_JSON) public void setUsedPackage( ??? ) { ??? }Actually I would like to receive a json-message as post-data like: {"PackageID":"12345","Used":"false"}
My question is: What do I have to replace the "???" with?
For GET-Methods it is:
@QueryParam("ID") String inputWhich allows me to access the variable specified as ID by using input.
Everything I've found so far didn't quite address the problem I face..
最满意答案
对于JAXRS webservice,您可以创建一个注释类,它映射到您的json,例如
import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Package { private String packageID; private Boolean used; // getters and setters here }然后 ??? 将是你的班级
public void setUsedPackage(Package package)当你发布你的json时,你需要将Content-type头指定为application / json
这里有一个我发现可能有帮助的jaxrs教程
http://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/post-example/
For a JAXRS webservice you can create an annotated class that maps to your json e.g.
import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Package { private String packageID; private Boolean used; // getters and setters here }then ??? will be your class
public void setUsedPackage(Package package)When you post your json you'll need to specify the Content-type header as application/json
Here's a jaxrs tutorial I found that may help
http://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/post-example/
发布评论