圖片控制器具有如下功能:運行/執行在GSP /視圖的查詢Grails中
def scaled = {
log.debug("SCALED IMAGE " + params)
response.setContentType('image/jpeg')
response.setHeader('Cache-control', 'no-cache')
def userId = session.selectedUser.id
if(params.userId){
userId = params.userId
}
if(params?.id != null && !(params?.id.empty)){
params.maxWidth?: 20.00
params.maxHeight?: 20.00
response.outputStream << imageProxyService.loadImage(params.id, securityService.passwordEncoder(userId.toString()),params.maxWidth, params.maxHeight)
}
}
和個人資料照片的文件名被存儲在用戶表中。 用戶有很多狀態,我想根據顯示的狀態加載用戶的個人資料照片。我的狀態GSP看起來是這樣的:
<g:each in="${statusList}" status="i" var="status" status="i">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<tr><td><img id="profile_photo" src="${createLink(controller:'image', action:'profilePhoto', id:status.photo)}" alt="" title="" />
</td></tr>
</tr>
</g:each>
查詢我的狀態控制器用於:
def alllist = {
log.debug("BEGIN IWI PROFILE")
def statusList = []
def sql = new Sql(dataSource);
def statusQuery = """SELECT c.id, c.status_message, c.status_type as profile, se.id, se.photo FROM user_account se, status c
WHERE
c.user_account_id = se.id
GROUP BY se.id, c.id, c.status_message, c.status_type, se.photo"""
def result = sql.rows(statusQuery);
def userQuery = """not sure """
if (result){
log.debug("GOT SOME RESULTS IN PERSONAL user" + result)
result.each() { status ->
def userResult = sql.firstRow(userQuery, [status.id])
if (userResult){
status['userId'] = userResult.id
} else {
status['userId'] = ""
}
statusList += status
}
}
render(template: "alllist", model: [statusList: statusList])
請注意:這種方式我收到的所有照片都正確的,但照片只用於會話的用戶顯示。
<img id="profile_photo" src="/myApp/image/profilePhoto/9edd692580d148c791c6c2aa3510605a95ba6de6.jpg" alt="" title=""/>
你可以發佈你的域對象? – leebutts
請檢查更新後的問題 – desicreatioNZ