Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pagination 如何重写CRUD/list()函数?玩框架_Pagination_Playframework_Crud - Fatal编程技术网

Pagination 如何重写CRUD/list()函数?玩框架

Pagination 如何重写CRUD/list()函数?玩框架,pagination,playframework,crud,Pagination,Playframework,Crud,我试图为我的一个模型重写CRUD模块的list()函数 我在谷歌群组上发现了这一点,这正是我面临的问题 基本上,我想根据认证类别筛选列表,我尝试了以下方法: 控制器 public static void list(string category){ List<Duty> object = Duty.getByCategory(category); render(object); } 公共静态无效列表(字符串类别){ 列表对象=职责。getByCategory(类别)

我试图为我的一个模型重写CRUD模块的list()函数

我在谷歌群组上发现了这一点,这正是我面临的问题

基本上,我想根据认证类别筛选列表,我尝试了以下方法:

控制器

public static void list(string category){
    List<Duty> object = Duty.getByCategory(category);
    render(object);
}
公共静态无效列表(字符串类别){
列表对象=职责。getByCategory(类别);
渲染(对象);
}
模型

公共静态列表getByCategory(字符串类别){
列表结果=任务。查找(“从任务d联接中选择不同的d”+
“d.category c,其中c.name=?按d.name排序”,category).fetch();
返回结果;
}
我得到以下错误:

如何覆盖列表操作


任何帮助都将不胜感激。

似乎您正在覆盖控制器,而不是模板。CRUD列表方法的签名与您的略有不同:

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);
        }
    }
publicstaticvoid列表(int页、字符串搜索、字符串搜索字段、字符串orderBy、字符串顺序){
ObjectType=ObjectType.get(getControllerClass());
notFoundIfNull(类型);
如果(第<1页){
page=1;
}
List objects=type.findPage(页面、搜索、搜索字段、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”);
试一试{
呈现(类型、对象、计数、总计数、页面、orderBy、order);
}捕获(TemplateNotFounde异常){
呈现(“CRUD/list.html”、类型、对象、计数、总计数、页面、orderBy、order);
}
}

您会注意到render()传递的参数比您传递的要多得多,而且它们可能不是可选的。尝试为它们提供值。

您可以覆盖CRUD list方法,并在中添加通过许多参数的过滤器,例如:

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;
    }
    String where = "nameAttribute =" + value;

    List<Model> objects = type.findPage(page, search, searchFields, orderBy, order, where);
    Long count = type.count(search, searchFields, where);
    Long totalCount = type.count(null, null, where);
    try {
        render(type, objects, count, totalCount, page, orderBy, order);
    } catch (TemplateNotFoundException e) {
        render("CRUD/list.html", type, objects, count, totalCount, page, orderBy, order);
    }
}
publicstaticvoid列表(int页、字符串搜索、字符串搜索字段、字符串orderBy、字符串顺序){
ObjectType=ObjectType.get(getControllerClass());
notFoundIfNull(类型);
如果(第<1页){
page=1;
}
字符串,其中=“nameAttribute=”+值;
List objects=type.findPage(页面、搜索、搜索字段、orderBy、order、where);
长计数=type.count(搜索,搜索字段,其中);
Long totalCount=type.count(null,null,其中);
试一试{
呈现(类型、对象、计数、总计数、页面、orderBy、order);
}捕获(TemplateNotFounde异常){
呈现(“CRUD/list.html”、类型、对象、计数、总计数、页面、orderBy、order);
}
}

尝试从
视图(xtml)
调用该覆盖方法


并使用前面的代码,在
where=“…”

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;
    }
    String where = "nameAttribute =" + value;

    List<Model> objects = type.findPage(page, search, searchFields, orderBy, order, where);
    Long count = type.count(search, searchFields, where);
    Long totalCount = type.count(null, null, where);
    try {
        render(type, objects, count, totalCount, page, orderBy, order);
    } catch (TemplateNotFoundException e) {
        render("CRUD/list.html", type, objects, count, totalCount, page, orderBy, order);
    }
}
<form action="@{Controler.overrideList()}"  method="POST">