如果我使用' web-send-json-response =" true"'在调用任何服务时,它使用WebFacadeImpl.groovy的sendJsonResponse(Object responseObj)方法返回json响应。 它增加错误的地方'如果' eci.getMessage()。hasError()'真正。但是,有没有理由为什么不在Json Response中添加消息?
由于我愿意在json响应中有消息,所以我在sendJsonResponse()方法中添加了几行。 代码块我添加了几行来向json响应添加消息:
} else if (responseObj != null) {
responseObj.put("messages", eci.message.messages)
JsonBuilder jb = new JsonBuilder()
jb.call(responseObj)
jsonStr = jb.toString()
response.setStatus(HttpServletResponse.SC_OK)
} else {
jsonStr = ""
if (eci.message.messages) {
responseObj.put("messages", eci.message.messages)
JsonBuilder jb = new JsonBuilder()
jb.call(responseObj)
jsonStr = jb.toString()
}
response.setStatus(HttpServletResponse.SC_OK)
}
它工作正常,我在json响应中收到消息。