当前位置:编程学习 > JAVA >>

velocity 高手请进

第一次,我写成这样:
#foreach($col in $ShortColSubListtable.get(119))
 $col.id
#end
结果:127 128 129,结果没问题。

第二次,写成这样:
#foreach($index in [127..129])
  $ShortContListinColtable.get($index)
#end
结果:com.future.cms.pojo.Content@10e1619[id=336], com.future.cms.pojo.Content@1ccda6a[id=335]...
, 能拿到值,没问题的

第三次,写成这样:
#foreach($col in $ShortColSubListtable.get(119))
 $ShortContListinColtable.get($col.id)
#end

结果却是:$ShortContListinColtable.get($col.id) ... , 这种拿法取不到值,为什么? velocity --------------------编程问答--------------------  $ShortContListinColtable.get($col) 先这样取呢,没用过模板。 --------------------编程问答-------------------- $col 是个栏目对象,$ShortContListinColtable.get() 传递进去的应该是 $col 的id值,即 $col.id --------------------编程问答--------------------
#foreach($col in $ShortColSubListtable.get(119))
 #set($tes = $col.id)
 $ShortContListinColtable.get($tes)
#end --------------------编程问答-------------------- 这种写法也试过还是不行,这是结果:$ShortContListinColtable.get($tes) $ShortContListinColtable.get($tes) $ShortContListinColtable.get($tes) --------------------编程问答--------------------
#foreach($col in $ShortColSubListtable.get(119))
 #set($test = ${col}.id)
 $ShortContListinColtable.get($test)
#end
再看看能取到数据不?
#foreach($col in $ShortColSubListtable.get(119))
 $ShortContListinColtable.get("127")
#end --------------------编程问答-------------------- 这个报错了。。。
#foreach($col in $ShortColSubListtable.get(119))
 #set($test = ${col}.id)
 $ShortContListinColtable.get($test)
#end

这个没问题,能拿到数据
#foreach($col in $ShortColSubListtable.get(119))
 $ShortContListinColtable.get("127")
#end
--------------------编程问答-------------------- 我就很奇怪了。

 ## 1这个应该也是可以的吧。
#foreach($col in $ShortColSubListtable.get(119))
 #set($test = "127")
 $ShortContListinColtable.get($test)
#end

 ## 2真搞不定。
#foreach($col in $ShortColSubListtable.get(119))
  $ShortContListinColtable.get(${col.id})
  
#end
 如果1可以的话。怀疑你的$col.id 是int类型的然后传入必须是string 的。没有过veloctiy 不知道说的对不对。

--------------------编程问答-------------------- #foreach($col in $ShortColSubListtable.get(119))
 $ShortContListinColtable.get("$col.id")
#end
这样传依然不行啊,晕死了 --------------------编程问答-------------------- 还没有解决,自己顶一下!
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,