代码拉取完成,页面将自动刷新
同步操作将从 huifer/Code-Analysis 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
org.springframework.web.context.request.AbstractRequestAttributesScope
RequestAttributes
, 从 RequestAttributes
通过 name 获取属性实例
RequestAttributes
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
// 获取当前 request 的属性对象
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
// 属性对象中获取 name 对应的属性实例
Object scopedObject = attributes.getAttribute(name, getScope());
if (scopedObject == null) {
// object factory 创建
scopedObject = objectFactory.getObject();
// 设置到 request attributes 中
attributes.setAttribute(name, scopedObject, getScope());
// Retrieve object again, registering it for implicit session attribute updates.
// As a bonus, we also allow for potential decoration at the getAttribute level.
// 再一次获取
Object retrievedObject = attributes.getAttribute(name, getScope());
if (retrievedObject != null) {
// Only proceed with retrieved object if still present (the expected case).
// If it disappeared concurrently, we return our locally created instance.
scopedObject = retrievedObject;
}
}
return scopedObject;
}
Attribute
的时候需要调用 getScope
接下来了解其作用获取作用域标记
抽象方法
protected abstract int getScope();
返回的会有下列两种
RequestAttributes#SCOPE_REQUEST
RequestAttributes#SCOPE_SESSION
@Override
@Nullable
public Object remove(String name) {
// 获取当前 request attributes 对象
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
// 通过 name + 作用域 获取 属性实例
Object scopedObject = attributes.getAttribute(name, getScope());
if (scopedObject != null) {
// 删除属性实例
attributes.removeAttribute(name, getScope());
return scopedObject;
}
else {
return null;
}
}
@Override
public void registerDestructionCallback(String name, Runnable callback) {
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
attributes.registerDestructionCallback(name, callback, getScope());
}
通过org.springframework.web.context.request.ServletRequestAttributes#resolveReference
返回
HttpServletRequest
HttpSession
通过org.springframework.web.context.request.FacesRequestAttributes#resolveReference
返回
这里内容很多直接贴代码截图了
@Override
@Nullable
public Object resolveContextualObject(String key) {
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
return attributes.resolveReference(key);
}
AbstractRequestAttributesScope
拥有两个子类
org.springframework.web.context.request.RequestScope
org.springframework.web.context.request.SessionScope
getScope
和 getConversationId
public class RequestScope extends AbstractRequestAttributesScope {
@Override
protected int getScope() {
return RequestAttributes.SCOPE_REQUEST;
}
/**
* There is no conversation id concept for a request, so this method
* returns {@code null}.
*/
@Override
@Nullable
public String getConversationId() {
return null;
}
}
public class SessionScope extends AbstractRequestAttributesScope {
@Override
protected int getScope() {
return RequestAttributes.SCOPE_SESSION;
}
@Override
public String getConversationId() {
return RequestContextHolder.currentRequestAttributes().getSessionId();
}
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();
synchronized (mutex) {
return super.get(name, objectFactory);
}
}
@Override
@Nullable
public Object remove(String name) {
Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();
synchronized (mutex) {
return super.remove(name);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。