Last updated by wangyou
4 years ago
Builders
Hibernate Criteria Builder
The Hibernate Criteria Builder allows you to create queries that map to the Hibernate Criteria API. There are equivalent builder nodes for most criterion within the Hibernate Expression class. For more info see the Builders ReferenceThe builder can be used standalone by passing a persistent class and sessionFactory instance:new grails.orm.HibernateCriteriaBuilder(User.class, sessionFactory).list { eq("firstName", "Fred") }
def c = Account.createCriteria()
def results = c {
like("holderFirstName", "Fred%")
and {
between("balance", 500, 1000)
eq("branch", "London")
}
maxResults(10)
order("holderLastName", "desc")
}def c = Account.createCriteria()
def a = c.get {
eq("number", 40830994)
}def branchList = [ "London", "Newmarket", "Cambridge"] def c = Account.createCriteria() def results = c.list { or { for (b in branchList) { eq("branch", b) } } }
OpenRico Builder
Grails provides support for the OpenRico project. See this document for more details on how OpenRico handles response content. Using OpenRicoBuilder in controllers users can generate any response for OpenRico requests, see the example below which uses the Google API to retrieve search results and then creates an OpenRico ajax response.def result = google.doSearch(); new grails.util.OpenRicoBuilder(response).ajax { object(id:"googleAutoComplete") { for (re in result.resultElements) { div(class:"autoCompleteResult", re.URL) } } }