我有兩個表:酒店及內容的Grails:從相關表中顯示故障數據
內容域看起來是這樣的,正在生成hotelId:
class Content {
Hotel hotel
String imageUrl
static constraints = {
imageUrl nullable:true
}
我從上傳圖片到S3酒店的展示頁面到相關的內容表,這是行得通的 - 現在我想將我的內容表中的圖像顯示到相關酒店對象(其中酒店= 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>
這代碼將導致以下錯誤: '無法獲取'空對象'上的屬性'hotelId'。
任何幫助將不勝感激。
我只是想知道這個功能:findByHotelId。你確定這是正確的。在我看來,應該只有一個findByHotel() – Torsten
不,我不確定findByHotelId是否正確,但是我剛剛嘗試過使用findByHotel,並且遇到同樣的錯誤。這絕對是小東西一樣,雖然這是不對的 –
酒店賓館= Hotel.findById(params.id) 清晰內容= Content.findByHotel(酒店) 我彪這樣 – Torsten