2017-04-24 34 views
1

grails中的generate-all将与View(CRUD)一起生成控制器,我试图了解每个生成的代码块的影响,现在我似乎无法找到定义index.gsp中的{accountInstanceList}。grails - 查看定义中生成的实例

/views/account/index.gsp

 <g:each in="${accountInstanceList}" status="i" var="accountInstance"> 
      <tr class="${(i % 2) == 0 ? 'even' : 'odd'}"> 

       <td><g:link action="show" id="${accountInstance.id}">${fieldValue(bean: accountInstance, field: "firstname")}</g:link></td> 

       <td>${fieldValue(bean: accountInstance, field: "middlename")}</td> 

       <td>${fieldValue(bean: accountInstance, field: "lastname")}</td> 

       <td>${fieldValue(bean: accountInstance, field: "email")}</td> 

       <td>${fieldValue(bean: accountInstance, field: "role")}</td> 

      </tr> 
     </g:each> 

从我已经学会了说实例的定义应包括在控制器

/controller/.../AccountController.groovy

package ers 

import static org.springframework.http.HttpStatus.* 
import grails.transaction.Transactional 

@Transactional(readOnly = true) 
class AccountController { 

    static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"] 

    def index(Integer max) { 
     params.max = Math.min(max ?: 10, 100) 
     respond Account.list(params), model:[accountInstanceCount: Account.count()] 
    } 

    def show(Account accountInstance) { 
     respond accountInstance 
    } 

    def create() { 
     respond new Account(params) 
    } 

    @Transactional 
    def save(Account accountInstance) { 
     if (accountInstance == null) { 
      notFound() 
      return 
     } 

     if (accountInstance.hasErrors()) { 
      respond accountInstance.errors, view:'create' 
      return 
     } 

     accountInstance.save flush:true 

     request.withFormat { 
      form multipartForm { 
       flash.message = message(code: 'default.created.message', args: [message(code: 'account.label', default: 'Account'), accountInstance.id]) 
       redirect accountInstance 
      } 
      '*' { respond accountInstance, [status: CREATED] } 
     } 
    } 

    def edit(Account accountInstance) { 
     respond accountInstance 
    } 

    @Transactional 
    def update(Account accountInstance) { 
     if (accountInstance == null) { 
      notFound() 
      return 
     } 

     if (accountInstance.hasErrors()) { 
      respond accountInstance.errors, view:'edit' 
      return 
     } 

     accountInstance.save flush:true 

     request.withFormat { 
      form multipartForm { 
       flash.message = message(code: 'default.updated.message', args: [message(code: 'Account.label', default: 'Account'), accountInstance.id]) 
       redirect accountInstance 
      } 
      '*'{ respond accountInstance, [status: OK] } 
     } 
    } 

    @Transactional 
    def delete(Account accountInstance) { 

     if (accountInstance == null) { 
      notFound() 
      return 
     } 

     accountInstance.delete flush:true 

     request.withFormat { 
      form multipartForm { 
       flash.message = message(code: 'default.deleted.message', args: [message(code: 'Account.label', default: 'Account'), accountInstance.id]) 
       redirect action:"index", method:"GET" 
      } 
      '*'{ render status: NO_CONTENT } 
     } 
    } 

    protected void notFound() { 
     request.withFormat { 
      form multipartForm { 
       flash.message = message(code: 'default.not.found.message', args: [message(code: 'account.label', default: 'Account'), params.id]) 
       redirect action: "index", method: "GET" 
      } 
      '*'{ render status: NOT_FOUND } 
     } 
    } 
} 

{accountInstanceList}不在控制器的索引操作中,它在哪里定义?是否有隐藏的类也生成?

回答

0

渲染方法计算出的“东西”你想传递给视图类型和对象是DomainNameInstanceList域列表的情况下创建了一个合适的名称,请参阅类DefaultHtmlRenderer

另请参阅scaffollding部分文档

...the standard scaffold views expect model variables of the form 
<propertyName>InstanceList for collections and <propertyName>Instance 
for single instances 
+0

换句话说我不会看到实例的物理定义? – newbie

+0

你看什么意思? –

+0

我的意思是我不能转到accountInstanceList的定义? – newbie