java - Grails 分页问题

标签 java grails

I have a simple paginate issue and get the following error... 
Hoping for some advice. I am relearning grails using version 2.1 and when I attempt to make a page with the paginate section is it failing.


Error 500: Internal Server Error
URI
/tictoc/
Class
groovy.lang.MissingMethodException
Message
No signature of method: tictoc.Event.withCritera() is applicable for argument types: (tictoc.StoreController$_closure2_closure3) values: [tictoc.StoreController$_closure2_closure3@10cea05] Possible solutions: withCriteria(groovy.lang.Closure), withCriteria(java.util.Map, groovy.lang.Closure)
Around line 27 of grails-app\controllers\tictoc\StoreController.groovy
24:        
25:        def total = Event.countByActive(true)
26:        
27:        def eventList = Event.withCritera {
28:        
29:            eq 'active', params.active
30:            projections {
Around line 13 of grails-app\controllers\tictoc\StoreController.groovy
10:    def show = {
11:    
12:        log.error 'exec activeEvents'
13:        activeEvents()
14:
15:    }
16:

//这是域类,我正在使用 Activity 字段进行 withCritera 搜索。我希望它是一个 boolean 值,但我不确定它是否有效。

package tictoc

import java.math.BigInteger

class Event implements Cloneable {

    Integer id
    String name
    Date startDate
    Date endDate
    String desc
    String active 

    static constraints = {
        name(nullable:true)
        startDate(nullable:true)
        endDate(nullable:true)
        desc(nullable:true)
        active(nullable:true)
    }

    public String toString(){
        return "id:" + this.id + 
               " name:" + this.name + 
               " startDate:" + this.startDate +
               " endDate:" + this.endDate;
    }

    public int hashCode() {
        int hash = 1
        hash = hash * 31 + id.hashCode()
        hash = hash * 31 + name.hashCode()
        hash = hash * 31 + this.startDate
        hash = hash * 31 + this.endDate
        return hash
    }

    public boolean equals(Object anObject) {

        if (anObject != null &&
            anObject instanceof Event)
        {
            Ticket aThing = (Ticket)anObject;
            return (this.id == aThing.id) && 
                   (this.name == aThing.name) && 
                   (this.startDate == aThing.startDate) && 
                   (this.endDate == aThing.endDate)
        }

        return false;
    }
}

//这是 GSP,分页部分未显示下一个/上一个按钮:

<%@ page import="tictoc.Store" %>
<!doctype html>
<html>
    <head>
        <meta name="layout" content="main">
        <g:set var="entityName" value="${message(code: 'store.label', default: 'Store')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
    </head>
    <body>

        <h1> Ticket Store </h1>

        <table border=0 class="eventsTable">
            <tr>
                <th>Event</th>
                <th>Start </th>
                <th>End </th>
                <th>Description</th>
            </tr>
            <g:each var="event" in="${events}">

            <tr>
                <td>${event.name}</td>
                <td><g:formatDate format="MM/dd/yyyy" date="${event.startDate}"/></td>
                <td><g:formatDate format="MM/dd/yyyy" date="${event.endDate}"/></td>
                <td>${event.desc}</td>
            </tr>

            </g:each>
        </table>

        <div class="paginateButtons">
            <g:paginate controller="store"
                action="activeEvents"
                params="[name:active]"
                total="${totalEvents}" />
        </div>
    </body>
</html>

Here is the controller and i set the default page to activeEvents :

package tictoc

import tictoc.Event 

class StoreController {

    Event event
    static defaultAction = "activeEvents"

    def activeEvents = {
        log.error 'exec activeEvents'
        def max    = Math.min(params.max?.toInteger() ?:10, 100)
        def offset = params.offset?.toInteger() ?: 0
        def total = Event.countByActive(true)
        def eventList = Event.withCritera {

            eq 'active', params.active
            projections {
                event {

                    order 'name'
                }
            }
            maxResults max
            firstResult offset
        }

        return [events:eventList, 
                       totalEvents:total,
                       active:params.active]
    }
}

最佳答案

您已拼写 withCriteria错误。

关于java - Grails 分页问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9640910/

相关文章:

mongodb - 没有从连接参数中获取正确的mongo数据库,而是必须手动对其进行映射

grails - 是否可以在一对一的关系中使 nullable = true ?

unit-testing - 如何在Grails集成测试中的easyb方案之间清除数据库(域)?

multithreading - 任务数量未知的多线程

java - 正则表达式匹配一定长度的单词

java - AWT 窗口关闭监听器/事件

java - appcompat_v7 和 android-support-v7-appcompat 之间的区别?

java - 如何创建具有多种 View 类型的 RecyclerView

java - FFmpeg 命令帮助和文档指针

grails-plugin - Grails Mongodb插件安装问题