只是自己的想法,不对不要扔鸡蛋哦。
今天突发奇想的实现一个小小的cache。把分类categories放入map中,cache起来。
private void cache() {
if(log.isDebugEnabled()){
log.debug("Starting cache the categories");
}
cacheCategoryMap = new HashMap();
cacheCategoryMap.put("categories",categoryDao.getCategories());
}
然后我想在interceptor里面把categories写到ognlvaluestack里面这样我在ftl里面就可以<#list categories>....</#list>了。因为这个是在每个页面的header.ftl里面的。我也就不需要再每个action里面去get一下了。
刚开始我implements Interceptor
final OgnlValueStack stack = ActionContext.getContext().getValueStack();
stack.setValue("categories" ,categoryManager.getCategories());
return invocation.invoke();
可是这样也不可以。后来我想到是不是action执行完毕之后就把stack中的这个值清空了我又用了。AroundInterceptor 我想在after里面去设置不就可以了。
protected void after(ActionInvocation dispatcher, String result) throws Exception {
final OgnlValueStack stack = ActionContext.getContext().getValueStack();
stack.setValue("categories" ,categoryManager.getCategories());
}
可是这样还是不可以。我晕了。我想是不是要在action里面声明一下categories。
private List categories;
public List getCategories() {
return categories;
}
public void setCategories(List categories) {
this.categories = categories;
}
然后在before里面去get就可以了。
protected void before(ActionInvocation invocation) throws Exception {
final OgnlValueStack stack = ActionContext.getContext().getValueStack();
stack.setValue("categories" ,categoryManager.getCategories());
}
总算实现了。不过还要在每个action里面声明一下categories,这样还是很不好的。刚才有人建议用filter。我在试试吧.
http://leaf.jdk.cn/index.php/archives/91
分享到:
相关推荐
Postman-Interceptor下载
postman interceptor
Struts2_interceptor_和_filter区别
利用反射和动态代理机制实现自定义拦截器Interceptor http://blog.csdn.net/alanchen520/article/details/34087833
包含postman的chrome插件,postman-interceptor插件,离线安装,即可使用
通过代理和反射实现一个Interceptor框架
详细介绍struts2 interceptor
InterCeptor
Struts2拦截器(Interceptor) Struts2拦截器(Interceptor)
logging-interceptor-3.14.4的jar包,用于okhttp网络拦截器
postman 和 postman interceptor。亲测可用,里边有说明博客
Postman-Interceptor_v0.2.20 .Postman Interceptor必须和Postman联合使用。
免费Postman和Postman interceptor压缩包,Postman为文件夹,直接选择扩展程序中的 加载已解压的扩展程序 ,选择解压后的postman文件夹即可,postman-interceptor为crx文件,直接拖入到chrome://extensions/中即可
一个用于修改 ajax 请求响应的 chrome 扩展,修改ajax请求数据
Postman Interceptor 2022最新的版本 使用方法: 1,打开 chrome://extensions/ 2,解压文件夹 postman_interceptor-v1.1.2.7z 3,打开解压文件夹,拖动 ‘1.1.2_0’ 到 chrome://extensions/ postman interceptor v...
postman 和 postman interceptor。亲测可用。 说明博客https://blog.csdn.net/u012106306/article/details/90172863
Postman是chrome的一款插件,用于做接口请求测试,无论是前端,后台还是测试人员,都可以用postman来测试接口,用起来非常方便。希望可以对你有所帮助。
jfinal中拦截器(Interceptor)的参数注入jfinal中拦截器(Interceptor)的参数注入
postman+postman interceptor插件,下载后修改文件后缀为.zip,然后离线加载就可以了
postman-Interceptor同步浏览器请求到postman中,客户端版本postman和插件版都可以用