2

params によって生成され、コントローラーからサービスに渡されるタグのリストを取得するコードを次に示します。飲食店のリストをフィルタリングして、一致するタグ プロパティを持つ飲食店のみを含めようとしています。私はプログラミングとgrailsに慣れていないので、ばかげた間違いを許してください:

    class Eatery {
        String name
        String phone
        Date lastVisited
        List<Tag> tags
        static hasOne = [location: Location]
        static hasMany = [tags: Tag];
        static constraints = {
            name nullable: false, blank: false
            phone nullable: true, blank: true
            location nullable: true, blank: true
            tags nullable: true, blank: true
            lastVisited nullable: true, blank: true
        }
        public String toString() {
            return name
        }
}

サービス方法は次のとおりです。

Eatery getRandomEatery(List<Tag> tagList) {
    List<Eatery> eateryList = Eatery.findAllByTags(tagList)
    Random random = new Random()
    Integer n = eateryList.size()
    Integer selection = Math.abs(random.nextInt(n))
    Eatery eatery = eateryList.get(selection)
    return eatery
}

そして、ここにエラーがあります:

 Class
org.h2.jdbc.JdbcSQLException
Message
Parameter "#1" is not set; SQL statement: select this_.id as id2_0_, this_.version as version2_0_, this_.last_visited as last3_2_0_, this_.name as name2_0_, this_.phone as phone2_0_ from eatery this_ where this_.id=? [90012-164]
Around line 16 of grails-app/services/grubspot/RandomizerService.groovy
13://14://        }15:        List<Eatery> eateryList = Eatery.findAllByTags(tagList)16:        Random random = new Random()17:        Integer n = eateryList.size()18:        Integer selection = Math.abs(random.nextInt(n))19:        Eatery eatery = eateryList.get(selection)
4

2 に答える 2

1

変化する

List<Eatery> eateryList = Eatery.findAllByTags(tagList)

List<Eatery eateryList = Eatery.executeQuery("""
select e
from Eatery e left join e.tags as t
where t in (:tagList)""", [tagList: tagList])
于 2013-06-16T11:32:24.627 に答える
1

次のような条件でクエリを作成できると思います...

List<Eatery> eateryList = Eatery.withCriteria{
    tags {
        "in" "id", tagList.id
    }
}

テストしていませんが、アイデアを提供する必要があります

于 2013-06-17T08:44:26.907 に答える