本文整理匯總了Java中org.springframework.web.context.request.NativeWebRequest.getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java NativeWebRequest.getAttribute方法的具體用法?Java NativeWebRequest.getAttribute怎麽用?Java NativeWebRequest.getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.context.request.NativeWebRequest
的用法示例。
在下文中一共展示了NativeWebRequest.getAttribute方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
if(Oauth2Token.class.equals(parameter.getParameterType())){
return webRequest.getAttribute("Oauth2Token", RequestAttributes.SCOPE_REQUEST);
}
if(SNSUserInfo.class.equals(parameter.getParameterType())){
return webRequest.getAttribute("SNSUserInfo", RequestAttributes.SCOPE_REQUEST);
}
return null;
}
示例3: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
public Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
if(Oauth2Token.class.equals(parameter.getParameterType())){
return webRequest.getAttribute("Oauth2Token", RequestAttributes.SCOPE_REQUEST);
}
if(SNSUserInfo.class.equals(parameter.getParameterType())){
return webRequest.getAttribute("SNSUserInfo", RequestAttributes.SCOPE_REQUEST);
}
return null;
}
示例4: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container,
NativeWebRequest request, WebDataBinderFactory factory) throws Exception {
//獲取用戶ID
Object object = request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY, RequestAttributes.SCOPE_REQUEST);
if(object == null){
return null;
}
//獲取用戶信息
UserEntity user = userService.queryObject((Long)object);
return user;
}
示例5: 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;
}
示例6: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//取出存入的用戶ID
String currentUserId = (String) webRequest.getAttribute(Constant.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
if (currentUserId != null) {
return userDao.findById(currentUserId);
}
return new MissingServletRequestPartException(Constant.CURRENT_USER_ID);
}
示例7: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container,
NativeWebRequest request, WebDataBinderFactory factory) throws Exception {
//獲取用戶ID
Object object = request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY, RequestAttributes.SCOPE_REQUEST);
if (object == null) {
return null;
}
//獲取用戶信息
return userService.queryObject((Long) object);
}
開發者ID:davichi11,項目名稱:my-spring-boot-project,代碼行數:12,代碼來源:LoginUserHandlerMethodArgumentResolver.java
示例8: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
/**
* Construct new {@link AppSecret} object from the given Web request.
* The authenticated user is available in the web request principal.
*/
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webReq, WebDataBinderFactory binderFactory) throws Exception {
Authentication auth = (Authentication) webReq.getUserPrincipal();
OneOpsUser user = (OneOpsUser) auth.getPrincipal();
// Get the path variable.
@SuppressWarnings("unchecked")
Map<String, String> pathVars = (Map<String, String>) webReq.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, SCOPE_REQUEST);
String group = pathVars != null ? pathVars.get(APP_NAME_PARAM) : "";
String secret = pathVars != null ? pathVars.get(APP_SECRET_PARAM) : "";
AppGroup appGroup = new AppGroup(user.getDomain(), group);
return new AppSecret(secret, appGroup);
}
示例9: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
/**
* Construct new {@link AppGroup} object from the given Web request.
* The authenticated user is available in the web request principal.
*/
@Override
public AppGroup resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webReq, WebDataBinderFactory binderFactory) throws Exception {
Authentication auth = (Authentication) webReq.getUserPrincipal();
OneOpsUser user = (OneOpsUser) auth.getPrincipal();
// Get the path variable.
@SuppressWarnings("unchecked")
Map<String, String> pathVars = (Map<String, String>) webReq.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, SCOPE_REQUEST);
String group = pathVars != null ? pathVars.get(APP_NAME_PARAM) : "";
return AppGroup.from(user.getDomain(), group);
}
示例10: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
return webRequest.getAttribute("Oauth2Token", RequestAttributes.SCOPE_REQUEST);
}
示例11: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
public Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
return webRequest.getAttribute("Oauth2Token", RequestAttributes.SCOPE_REQUEST);
}