grails

def lognUser=UtilsController.getLoginUser(session)//取值页面登录人
def ask=KnowledgeAsk.findById(params.id)   //返回所有ID的记录


def findAnswer="%"+params.f1+"%"
like("title",findAnswer)//模糊查询

def findAsk=
{  
def lists,total,lists1
def findAnswer="%"+params.f1+"%"
def lognUser=UtilsController.getLoginUser(session)
        if(lognUser)
{
params.max = Math.min(params.max ? params.int('max') : 3, 100)
params.offset = params.int('offset') < 0 ? 0 : params.int('offset')
def cc=KnowledgeType.createCriteria()
lists=cc.list
   {
   isNull("parent")
   }
def fin=KnowledgeAsk.createCriteria()
lists1=fin.list
{
like("title",findAnswer)
order("dateCreated","desc")
firstResult(params.offset)
maxResults(params.max)
}
def fin1=KnowledgeAsk.createCriteria()
def lists2=fin1.list
{
isNull("title")
projections{ rowCount() }
}
total=lists2[0]

}
             render(view:"knowledgeList" ,model:[tiaojian:params.f1,lists1:lists1,lists:lists,total:total])  
}

遍历一个列表 并输出

           <g:each in="${lists}" status="i" var="list1">
           <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
           <td>${i+1 }</td>
          <td><a href="${request.getContextPath()}/knowledge/show/${list1.id}">${list1.title }</a></td>
           <td>${list1.dateCreated }</td>
           <td>${list1.founder}</td>
           </tr>、、、
表达一个满足关系
<g:if test="${list1.bestanswer ==null}">未解决</g:if><g:else>已解决</g:else>

你可能感兴趣的:(grails)