为了发送适当的响应,我需要检测经典HTTP GET请求,AJAX请求或g:include标记库是否已请求控制器操作。
例如,考虑以下代码段:
class CommunityController {
def show = {
def users = getUsers()
if (/* WHAT IS THE CODE HERE??? */) //g:include request => render 'show' template only
render template:'show', model=[users]
else if (request.xhr) //Ajax => we send JSON content
render users as JSON
else //Classic request => we render 'show' GSP page
[users]
}
}
...如何通过g:include标签lib?
检测到该动作已被调用谢谢。
答案 0 :(得分:5)
你可以这样测试:
import org.springframework.web.util.WebUtils
if (request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)) {
// request was included
}