本文整理汇总了Java中org.springframework.web.context.request.RequestAttributes.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java RequestAttributes.setAttribute方法的具体用法?Java RequestAttributes.setAttribute怎么用?Java RequestAttributes.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.request.RequestAttributes
的用法示例。
在下文中一共展示了RequestAttributes.setAttribute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adjustViewName
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
public static String adjustViewName(String viewName) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String jspPrefix = (String) requestAttributes.getAttribute("jspPrefix", RequestAttributes.SCOPE_REQUEST);
if (jspPrefix == null || "".equals(jspPrefix)) jspPrefix = comDefaultPath;
String jspPage = jspPrefix + viewName;
// LOG.debug("jspPage = " + jspPage);
// if tiles exist, forward tiles layout
String aTrgetId = (String) requestAttributes.getAttribute("curTrgetId", RequestAttributes.SCOPE_REQUEST);
String aCurMenuNo = (String) requestAttributes.getAttribute("curMenuNo", RequestAttributes.SCOPE_REQUEST);
if( aTrgetId != null
&& aTrgetId.startsWith("CMMNTY_")
&& aCurMenuNo != null
&& !"".equals(aCurMenuNo) ) {
requestAttributes.setAttribute("jspPage", jspPage, RequestAttributes.SCOPE_REQUEST);
return "forward:/cop/cmy/CmmntyTilesPage.do";
}
return jspPage;
}
示例2: getErrorAttributes
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
@Override
public Map<String, Object> getErrorAttributes(
RequestAttributes requestAttributes,
boolean includeStackTrace) {
Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, true);
Throwable throwable = getError(requestAttributes);
ErrorStatusCodeAndMessage errorStatusCodeAndMessage = exceptionStatusCodeAndMessageResolver
.resolveStatusCodeAndMessage(
throwable,
(String) errorAttributes.get("message"),
(Integer) requestAttributes.getAttribute("javax.servlet.error.status_code", 0));
errorAttributes.put("error", errorStatusCodeAndMessage.getMessage());
requestAttributes.setAttribute("javax.servlet.error.status_code", errorStatusCodeAndMessage.getStatusCode(), 0);
errorAttributes.put("status", errorStatusCodeAndMessage.getStatusCode());
log.error(
errorStatusCodeAndMessage.getMessage(),
StructuredArguments.keyValue("errorCode", errorStatusCodeAndMessage.getMessage()),
StructuredArguments.keyValue("stackTrace", errorAttributes.get("trace"))
);
if (!globalIncludeStackTrace) {
errorAttributes.remove("exception");
errorAttributes.remove("trace");
}
errorAttributes.remove("message");
return errorAttributes;
}
示例3: setWxRequestToRequest
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
/**
* 同上面方法,不过request从RequestContextHolder中取
* @param wxRequest
*/
public static void setWxRequestToRequest(WxRequest wxRequest) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null) {
requestAttributes.setAttribute(WX_REQUEST_ATTRIBUTE, wxRequest, RequestAttributes.SCOPE_REQUEST);
}
}
示例4: isValid
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
/**
* 数据验证
*
* @param target
* 验证对象
* @param groups
* 验证组
* @return 验证结果
*/
protected boolean isValid(Object target, Class<?>... groups) {
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(target, groups);
if (constraintViolations.isEmpty()) {
return true;
} else {
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
requestAttributes.setAttribute(CONSTRAINT_VIOLATIONS_ATTRIBUTE_NAME, constraintViolations, RequestAttributes.SCOPE_REQUEST);
return false;
}
}
示例5: addLog
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
/**
* 添加日志
*
* @param content
* 内容
*/
protected void addLog(String content) {
if (content != null) {
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
requestAttributes.setAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME, content, RequestAttributes.SCOPE_REQUEST);
}
}
示例6: cmmntyMainPageHandler
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
private String cmmntyMainPageHandler(
String cmmntyId,
String menuId,
String contentUrl) {
if( cmmntyId == null || cmmntyId.equals("") ) {
throw new RuntimeException("cmmntyId not found");
}
CommunityVO communityVO = cmmntyService.getCommunityInfo(cmmntyId, menuId);
// --------------------------------
// 컨텐트 URL 정보
// --------------------------------
if( "".equals(menuId) && communityVO.getTopMenuList().size() != 0 ) {
menuId = communityVO.getTopMenuList().get(0).get("menuNo").toString();
}
if( "".equals(contentUrl) ) {
contentUrl = getMenuInfo(communityVO, menuId, "chkURL");
if( "".equals(contentUrl) ) {
contentUrl = "/cop/cmy/CmmntyMainContents.do";
}
}
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
requestAttributes.setAttribute("curTrgetId", communityVO.getCmmntyId(), RequestAttributes.SCOPE_REQUEST);
requestAttributes.setAttribute("curMenuNo", menuId, RequestAttributes.SCOPE_REQUEST);
return "forward:"+contentUrl;
}
示例7: setAttribute
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
@Override
public void setAttribute(RequestAttributes request, String name, Object value) {
request.setAttribute(name, value, RequestAttributes.SCOPE_SESSION);
}
示例8: tagWithException
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
public static void tagWithException(Throwable exception) {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
attributes.setAttribute(EXCEPTION_ATTRIBUTE, exception,
RequestAttributes.SCOPE_REQUEST);
}
示例9: setWxWebUserToSession
import org.springframework.web.context.request.RequestAttributes; //导入方法依赖的package包/类
public static void setWxWebUserToSession(WxWebUser wxWebUser) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null) {
requestAttributes.setAttribute(WX_SESSION_USER, wxWebUser, RequestAttributes.SCOPE_SESSION);
}
}