Grails:显示相关表格中的数据时出现问题

时间:2017-04-17 12:17:57

标签: grails controller

我有两张桌子:酒店和内容

Content域看起来像这样,正在生成hotelId:

class Content {

Hotel hotel
String imageUrl

static constraints = {
   imageUrl nullable:true
}

我正在将图像从酒店的展示页面上传到S3到相关的内容表,这是有效的 - 现在我想将我的内容表中的图像显示到相关酒店对象的显示页面(其中来自内容的hotel = hotelId的id。

我已经在这里待了几天,这就是我最接近纠正的地方:

HotelController:

def showContent() 
{
    def content = Content.findByHotelId( hotel.params.id )
    render content: content
}

酒店视图:

<g:if test="${content.hotelId}" action="showContent">
     <img src = "${content.imageUrl}" />
</g:if>

此代码导致以下错误: &#39;无法获得房产&#39; hotelId&#39;在null对象&#39;。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

坚持HotelController中的标准脚手架展示动作:

def show(Hotel hotel) {
        respond hotel
}

然后对于酒店show.gsp中的每个内容:

<g:each in="${hotel.contents}" var="content">
    <img src = "${content.featuredImageUrl}" />
</g:each>

我猜你想要以某种方式将上述每一个包装成div或风格。

相关问题