版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
screenshot.png 可知上面时序图完成了对RequestScope对象定义的修改创建了代理bean,具体修改内容是修改了beanClass为ScopedProxyFactoryBean,并且保存了原来的 return getBeanFactory().getBean(getTargetBeanName()); } 所以最后是从IOC获取目标类bean.下面看下getBean代码: //获取RequestScope throw new IllegalStateException("No Scope registered for scope '" + scopeName + "'"); } try { //调用RequestScope defining a scoped proxy for this bean if you intend to refer to it from a singleton", ex); } requestscope
一、前言 最近我们组在做项目分层模块化项目调研,就产生一个问题如何在开启的线程中不破坏使用习惯情况下使用请求线程里面的RequestScope作用域的bean,感觉这个问题比较有意思就研究并整理下一下 screenshot.png 下面重点看RequestScope的get方法: public Object get(String name, ObjectFactory objectFactory RequestContextHolder.setRequestAttributess设置了设置了requestAttributesHolder,所以在test方法内第一次调用getAesKey()方法时候,RequestScope.get 调用setAesKey时候RequestScope.get()则是直接从attributes里面获取返回,然后在cglib代理里面调用pvginfo的setAesKey方法设置。 在子线程中调用getAesKey方法时候,RequestScope.get()方法里面第一步时候获取attributes时候,由于(5)是threadlocal,所以根据第二节讲的threadlocal
}
${requestScope.stu.age}
${requestScope.stu.birthday}
<%--备注:--%>
<%--1、name、age、birthday是JavaBean的属性名 }
${requestScope.stu.age}
${requestScope.stu.birthday}
<%--备注:--%>
<%--1、name、age、birthday [0]}
${requestScope.list[1]}
${requestScope.list[2].name}
</body>
</html>
运行结果:
5、获取Map }
${requestScope.stu.age}
${requestScope.stu.birthday}
<%--备注:--%>
<%--1、name、age、birthday }
<%--判断是否不为空且长度大于0--%>
${not empty requestScope.str}
</body>
</html>
运行结果:
隐式对象:
概念:就是EL中不用创建,拿来可以直接用的对象
</c:if> <%--判断是否为奇数--%> <c:if test="${<em>requestScope</em>.num % 2 ! = 0}">
-- 1、可以往域中保存数据 -->
保存之前:${ requestScope.key1 }
<c:set scope="request" var="key1" value="value1"></c:set>
保存之后:${ requestScope.key1 }
}">
操作符号:<input type="radio" name="op" value="+"${requestScope.cal.op=="+"?" checked":""}>+
<input type="radio" name="op" value="-" ${requestScope.cal.op=="-"?" checked":""}>-
<input type="radio" name="op" value="*" ${requestScope.cal.op=="*"?" checked":""}>*
<input type="radio" name="op" value="/" ${requestScope.cal.op=="/"?" checked":""}>/
操作数2:<input type="text" name="num2" value=" ${<em>requestScope</em>.cal.num2 }"><br
; } } 在ModelAndView中添加视图名,使用addObject添加数据 编写Jsp,获取数据 <html> <body>
}; {requestScope.person[‘name’]}; List里面的第二个数据 <%
<%
List list=new ArrayList();
list.add(“a”);
list.add (“b”);
list.add(“c”);
request.setAttribute(“List”,list);
%>
{requestScope.List[1]}; {requestScope.List [‘name’]};
我的年龄:<requestScope.person.name>
//什么方便? ${requestScope[‘my person’].name};
map.put(“my person”,new Person(“Xxx”,12));
*/
EL能进行的运算? =)
逻辑运算(&&,||)
empty运算(推断一个数据是否是空)
(null,空字符串,空集合)
{empty name}
三目条件运算 {requestScope.person.age
<c:choose> <c:when test="${<em>requestScope</em>.newFlag== '1' || <em>requestScope</em>.newFlag== '2' ||<em>requestScope</em>.newFlag
; // 已授权范围 Set<String> authorizedScope = adapter.identifyPermissionScope(authToken, requestScope ) { this.supplier = supplier; } /** * 验证权限范围 * @param token * @param requestScope * @return */ public Set<String> identifyPermissionScope(String token, Set<String> requestScope ; } if (requestScope == null) { return null; } if (requestScope.contains (authorizeScope); return requestScope; } } 此处为了方便设置,有两个关键字范围 AUTH_ALL:预设所有范围,全开放的意思,为数据库预先设置值
> 90 }">
<form action="/translateHandle" method="get"> <c:forEach begin="1" end="${<em>requestScope</em>.textNum}" forEach> 复选框标题:<input tepe="text" name="checkBoxTitle">
<c:forEach begin="1" end="${<em>requestScope</em>.checkBoxNum text" name="checkBoxText${i}">
</c:forEach> <input type="hidden" name="textNum" value="${<em>requestScope</em>.textNum }"> <input type="hidden" name="checkBoxNum" value="${<em>requestScope</em>.checkBoxNum}"> <button type
> 190 }">
); modelMap.put("gender", "male"); return "hello"; // 页面获取 // names:${requestScope.names } // time:${requestScope.time} // city:${requestScope.city } // request :${requestScope.request} // gender:${requestScope.gender } } 所有代码:SpringMVCDemo .java } // time:${requestScope.time} // city:${requestScope.city } // request :${requestScope.request} // gender:${requestScope.gender } } } SpringMVC的接参和传参的方式有很多种
city", "ChengDu");
7 modelMap.put("gender", "male");
8 return "hello";
9 }
JSP页面
1 1、time:${requestScope.time }
2
2、names:${requestScope.names }
3
3、city:${requestScope.city }
4
4、gender:${requestScope.gender
; charset=UTF-8"> <title>Insert title here</title> </head> <body>
EL获取特定域中的属性
pageScope----------------pageContext域
requestScope------------request域
sessionScope------ }
<c:set scope="request" var="name" value="王五"></c:set>
域对象保存数据之后:${requestScope.name}
50}">
empty requestScope.pageInfo.list}"> <c:forEach items="${<em>requestScope</em>.pageInfo.list }); // 初始化分页导航条 function initPagination(){ // 获取总记录数 var totalRecord = ${<em>requestScope</em>.pageInfo.total adminId=${admin.id}&pageNum=${<em>requestScope</em>.pageInfo.pageNum}&keyword=${param.keyword}" class="btn btn-primary action="admin/update.html" method="post" role="form"> <input type="hidden" name="id" value="${<em>requestScope</em>.admin.id 邮箱地址</label> <input type="email" class="form-control" id="inputEmail" name="email" value="${<em>requestScope</em>.admin.email
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
ID:${requestScope.czy.id }
编号:${ requestScope.czy.dlh}
姓名:${ requestScope.czy.name}
部门:${ requestScope.czy.bmmc