【问题标题】:ArrayList and Map problem in grailsgrails中的ArrayList和Map问题
【发布时间】:2010-04-12 16:14:05
【问题描述】:

我有一个包含地图的服务:

static Map cargosMap = ['1':'item1','2':'item 2','3':'item 3']

通过服务中的方法返回:

 static Map getCargos() {
    [cargosMap]
 }

控制器这样称呼它:

def mform = {

    Map cargos = empService.getCargos()

    [cargos:cargos]
}

在 gsp 中,我有选择:

<g:select name="cg1" from="${cargos}" />

但我遇到了异常:

 Error 500: Executing action  ....caused exception: 
   org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object
   ...  
   with class 'java.util.ArrayList' to class 
  'java.util.Map'

有什么线索吗?谢谢

【问题讨论】:

    标签: exception grails arrays map


    【解决方案1】:

    在我看来,您将地图包装在 getCargos() 的 ArrayList 中。为什么不只是:static getCargos() { cargosMap }。或者,更好的是,只需将 cargosMap 重命名为 cargos,Groovy 就会为您创建 getter。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      相关资源
      最近更新 更多