Gorm findAllBy inside gsp doubt
can anybody tell me why this works
<g:each var="n" in="${com.pp.News.list()}">
<h2>${n.t}</h2>
<p>${n.tx}</p>
</g:each>
but this doesn't ?
<g:set var="news" value="${com.pp.News.fi开发者_如何学GondAllByShow(true,[sort:'prio', order:'desc',max:5])}" />
<g:each var="n" in="news">
<h2>${n.t}</h2>
<p>${n.tx}</p>
</g:each>
Part of the exception is
Exception Message: No such property: t for class: java.lang.String
How can I make it work?
Thanks
Change
<g:each var="n" in="news">
to
<g:each var="n" in="${news}">
You are iterating over "news" instead of the returned result in the news var.
You should make it work by putting non-UI code in the controller or a service, and passing the data to the views in the model. It's a really bad idea to do database work or other business logic in a GSP/JSP/etc. MVC is about separating concerns.
精彩评论