2017-09-04 14 views
0

안녕하세요 저는 Grails에서 매우 새로 왔으며 grails에서 아주 간단한 질문을했습니다. 누군가 나를 도울 수 있기를 바랍니다.Grails f : 필드 표시 드롭 다운

class Person { 

    String name // name of the person 
    Date dob  // date of birth 

} // end of class 

나는 이미 내 데이터베이스에 몇 사람의 항목이 다음과 같이

나는 간단한 도메인 클래스 사람이있다.

다른 양식에서는 사용자가 드롭 다운 목록에서 21 세 이상 인 사람의 이름을 선택하도록하고 싶습니다. 지금은 다음과 같습니다

<fieldset class="form"> 

    <f:field bean="Person" property="name" /> 

</fieldset> 

어떻게 데이터베이스에서 모든 다른 사람을 필터링 할 이상에서만 21 세 사람의 이름을 표시?

미리 감사드립니다.

+0

당신이'Person.findAllByDobGreaterThanEquals (someVariableDate)를'사용하여 문서에서 확인할 수 있습니다 http://docs.grails.org/3.1.1/ref/Domain%20Classes/findAllBy.html – fsi

+0

감사 @fsi. 이 작품! –

답변

0

21 세 이상인 사람을 컨트롤러에서 검색 한 다음 gsp로 전달하여 표시합니다. 다음과 같은 내용 :

import groovy.time.TimeCategory 

def create() { 

// all your other codes 
def adults = Person.findAllByDobGreaterThanEquals(new Date() - 21.year) 

// other codes.... 
respond new Person(params), model:[adults :adults] 
} 

그런 다음 결과 집합과 함께 gsp에 표시하십시오.

<fieldset class="form"> 

    <f:field bean="Person" property="name" > 
     <g:select name="name" from="${adults}" optionKey="id" /> 
    </f:field> 

</fieldset>