playframework 是否可以覆盖 CRUD 控制器中的默认保存操作并重定向到列表

发布于 2024-10-07 06:44:46 字数 768 浏览 0 评论 0原文

我正在使用 Play 框架的出色的 CRUD 模块。问题是我想在保存我的对象之前进行一些特殊的处理和验证。所以我在 CRUD 控制器中创建了一个保存操作。到目前为止,一切都很好。但现在保存对象后,我想渲染对象列表,就像在覆盖其保存操作之前 CRUD 模块所做的那样。我该怎么做呢?

这是我的控制器:

package controllers.admin;

import java.util.List;

import models.Category;
import controllers.CRUD;

@CRUD.For(Category.class)
public class Categories extends CRUD {

     public static void save(Long id, Category category) {
         // Do my custom save process here

         //Redirect to the list page like CRUD was doing before I created this save action
     }

}

我尝试了不同的东西,例如 parent() [已弃用],这不是我想要的。我尝试了 CRUD.list() 但我需要传递我没有的参数。我还尝试了 render(admin/Categories/List.html, ??????); 但我需要传递一个列表,但我不知道该怎么称呼它。

任何帮助将不胜感激。

I'm using Play framework's great crud module. The thing is I would like to do some special processing and validation before my object gets saved. So I created a save action in my CRUD controller. So far so good. But now after the object is saved I would like to render the list of objects just like the CRUD module was doing before I overrode its save action. How would I go about doing this?

Here is my controller:

package controllers.admin;

import java.util.List;

import models.Category;
import controllers.CRUD;

@CRUD.For(Category.class)
public class Categories extends CRUD {

     public static void save(Long id, Category category) {
         // Do my custom save process here

         //Redirect to the list page like CRUD was doing before I created this save action
     }

}

I tried different things like parent() [Deprecated] not what I wanted. I tried CRUD.list() but I need to pass parameters which I don't have. I also tried render(admin/Categories/List.html, ??????); but I would need to pass a list and I don't know what to call it.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿得七秒忆 2024-10-14 06:44:46

你走在正确的道路上。最后只需调用 redirect(request.controller + ".list"); 它应该可以工作。

You're on the right path. At the end just call redirect(request.controller + ".list"); It should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文