简体   繁体   English

在POST请求中发送响应

[英]Send response in POST request

My route POST /article/create Application.create 我的路线POST /article/create Application.create

Application.java file Application.java文件

public static void create(Article article) {
   article.save();
  //send article ID (article.id) after saving

} }

Is it possible to send article.id as a response to the client once the article has been saved in the DB? 一旦将文章保存在数据库中,是否可以将article.id作为响应发送给客户端? If yes, what is the best way to do it 如果是,最好的方法是什么

You didn't specify which version of play you are using, but if it's play2 your method signature looks like missing return type. 您没有指定要使用的播放版本,但是如果使用的是play2,则方法签名看起来像缺少返回类型。

Please see more from here, and decide yourself how you want to return newly created id 请从此处查看更多信息,并自行决定如何返回新创建的ID

http://www.playframework.com/documentation/2.2.x/JavaResponse http://www.playframework.com/documentation/2.2.x/JavaResponse

You have several possibilities to return id 您有几种返回ID的可能性

  • headers
  • body of response 反应体
  • or even cookies 甚至饼干

Inside body you can return just id, or embed id inside json, xml, html or some other data structure. 在主体内部,您可以仅返回ID,也可以将ID嵌入json,xml,html或其他一些数据结构中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM