我正在用Java创建一个REST服务,现在我正在构建post方法,它有两个参数,必须在postman中作为xml输入(用于测试),并在java中作为xml获得响应,并将其插入到数据库中。
对于初学者,我尝试将这些值作为查询参数添加到POSTMAN with key和value中。响应为200,但xml为CUI=null Mesaj=null
这两个值都是空的,即使我在Postman中添加了两个键的值。
它怎么能看到这些值?这是java代码:
@Stateless
@Path("/cererepost")
public class HelloWorldResource {
Resp x = new Resp();
@EJB
private NameStorageBean nameStorage;
/**
* Retrieves representation of an instance of helloworld.HelloWorldResource
* @return an instance of java.lang.String
*/
@POST
@Produces("application/xml")
@Consumes(MediaType.APPLICATION_XML)
public Response postMsg(@PathParam("cui") String cui, @PathParam("mesaj") String mesaj) {
String xmlString = "CUI=" + cui + " Mesaj=" + mesaj;
Response response = Response.status(200).type(MediaType.TEXT_XML).entity(xmlString).build();
return response;
}}
我应该修改什么才能看到我在postman生成的xml中发送的post参数值?
提前感谢
发布于 2019-10-21 16:24:54
@PathParam("cui") String cui此行显示来自客户端的值应该作为路径参数传递,而不是查询字符串,如下所示:
更正:/cererepost/some_value
如果您希望在服务器端以查询字符串参数的形式获取它们,请将@PathParam("cui")更改为@QueryParam("cui")。
要了解query string和path variables之间的区别,请查看this post。
https://stackoverflow.com/questions/58482344
复制相似问题