本文整理匯總了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);
}
}