如何重写CRUD/list()函数?玩!框架 [英] How to override the CRUD/list() function? Play! framework

查看:88
本文介绍了如何重写CRUD/list()函数?玩!框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的一个模型覆盖CRUD模块的list()函数.

I'm trying to override the list() function of the CRUD module for one of my models.

我在Google网上论坛上找到了本质上是我遇到的问题.

I found this on google groups which is essentially the issue i'm having.

基本上我想根据凭证类别对列表进行过滤,我尝试过:

Basically I want to filter the list based on certian categories, I tried this:

控制器

public static void list(string category){
    List<Duty> object = Duty.getByCategory(category);
    render(object);
}

模型

public static List<Duty> getByCategory(String category){
    List<Duty> result = Duty.find("select distinct d from Duty d join " +
        "d.category c where c.name = ? order by d.name", category).fetch();
    return result;
}

我收到以下错误:

您如何覆盖列表操作?

任何帮助将不胜感激.

推荐答案

似乎您要覆盖控制器,而不是模板. CRUD列表方法的签名为此一个,与您的稍有不同:

It seems that you are overriding the controller but not the template. The signature of the CRUD list method is this one, slightly different that yours:

public static void list(int page, String search, String searchFields, String orderBy, String order) {
        ObjectType type = ObjectType.get(getControllerClass());
        notFoundIfNull(type);
        if (page < 1) {
            page = 1;
        }
        List<Model> objects = type.findPage(page, search, searchFields, orderBy, order, (String) request.args.get("where"));
        Long count = type.count(search, searchFields, (String) request.args.get("where"));
        Long totalCount = type.count(null, null, (String) request.args.get("where"));
        try {
            render(type, objects, count, totalCount, page, orderBy, order);
        } catch (TemplateNotFoundException e) {
            render("CRUD/list.html", type, objects, count, totalCount, page, orderBy, order);
        }
    }

您会注意到render()正在传递您要执行的其他许多参数,并且它们可能不是可选的.尝试为其提供价值.

You will notice that render() is passing many more parameters that you do, and probably they are not optional. Try to provide values for them.

这篇关于如何重写CRUD/list()函数?玩!框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆