//作者domain class Author { //作者姓名 String name static constraints = { } String toString() { this.name } }
//图书domain class Book { //作者 Author author //书名 String title static constraints = { } }
//条件查询action def search(Integer max){ params.max = Math.min(max ?: 10, 100) def criteria = Book.createCriteria() def list = criteria.list(params){ if(params.title){ like("title", "%${params.title}%") } if(params.authorName){ author{ like("name", "%${params.authorName}%") } } } respond list, model:[bookCount: list.totalCount], view: "index" }