我create
在 Play 中有一个动作!应该返回 HTTP 状态代码Created
并将客户端重定向到创建对象的位置的框架控制器。
public class SomeController extends Controller {
public static void create() {
Something something = new Something();
something.save();
response.status = StatusCode.CREATED; // Doesn't work!
show(something.id);
}
public static void show(long id) {
render(Something.findById(id));
}
}
另请参阅Play 中的方法链接!框架文档。
上面的代码返回状态码302 Found
而不是201 Created
. 我该怎么做才能让 Play 返回正确的状态(和Location
标题)?