本文整理汇总了Java中org.springframework.web.context.request.NativeWebRequest.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java NativeWebRequest.setAttribute方法的具体用法?Java NativeWebRequest.setAttribute怎么用?Java NativeWebRequest.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.request.NativeWebRequest
的用法示例。
在下文中一共展示了NativeWebRequest.setAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequestBody
import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
private String getRequestBody(NativeWebRequest webRequest) {
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
String body = (String) webRequest.getAttribute(JSON_BODY_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST);
if (StringUtils.isBlank(body)) {
try {
body = IOUtils.toString(servletRequest.getInputStream(), Charset.forName("UTF-8"));
webRequest.setAttribute(JSON_BODY_ATTRIBUTE, body, NativeWebRequest.SCOPE_REQUEST);
} catch (IOException e) {
throw new ParameterResolverException("参数解析失败", e);
}
}
return body;
}
示例2: getRequestBody
import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
private String getRequestBody(NativeWebRequest webRequest) {
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
String jsonBody = (String) webRequest.getAttribute(JSON_BODY_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST);
if (jsonBody == null) {
try {
jsonBody = IOUtils.toString(servletRequest.getInputStream(), "UTF-8");
webRequest.setAttribute(JSON_BODY_ATTRIBUTE, jsonBody, NativeWebRequest.SCOPE_REQUEST);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return jsonBody;
}