1
我想創建一個將查詢字符串附加到actualUrl的Grails資源映射器。迄今爲止所有的嘗試都失敗了 - 但也許我會以錯誤的方式去做事。示例代碼如下;如何使用映射器將自定義查詢字符串附加到grails資源?
import org.grails.plugin.resource.mapper.MapperPhase
import org.apache.commons.logging.LogFactory
class GlobalizationResourceMapper {
def log = LogFactory.getLog(this.class)
def phase = MapperPhase.RENAMING
def operation = "globalizationquerystring"
def priority = -1
static defaultExcludes = ['**/*.png', '**/*.gif', '**/*.jpg', '**/*.jpeg', '**/*.gz', '**/*.zip']
static defaultIncludes = ['**/*.js','**/*.gsp']
/**
* Cache the resource based on current language in use. Do this by appending a query string on the resource URL indicating language.
*/
def map(resource, config) {
def query = [l:'en_US']
resource.actualUrl = resource.actualUrl + '?' + query.collect { it }.join('&')
if (log.debugEnabled) log.debug "Modified URL: ${resource.actualUrl}"
log.info "Modified URL: ${resource.actualUrl}"
}
}
實際的URL得到了適當的修改,但是請求的任何資源都以重定向循環和404結束。
什麼被傳遞到包裝封口的baseUrl不僅這個例子中的URL是'/js/foo.js'。這是整個標記字符串,如'' – tuler 2012-04-23 04:24:19
我最終改變了我的解決方案, ''而不是。 – Cadriel 2012-08-07 00:51:41