# jfinal-shop **Repository Path**: waters_1/jfinal-shop ## Basic Information - **Project Name**: jfinal-shop - **Description**: jfinal4cms的电子商务插件 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2018-08-21 - **Last Updated**: 2021-09-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 一. Layout设计 /admin/admin_login.html: /admin/layout/login.html /layout/admin.html /layout/default.html /admin/blog/blog_list.html: /admin/blog/layout/list.html /admin/layout/blog.html /layout/admin.html /layout/default.html 二. 缓存设计 页面历史 基本概念: 项目中采用了J2-Cache.目的是简化缓存的管理,第一级缓存使用 Ehcache,第二级缓存使用 Redis 。由于大量的缓存读取会导致 L2 的网络成为整个系统的瓶颈,因此 L1 的目标是降低对 L2 的读取次数。该缓存框架主要用于集群环境中。单机也可使用,用于避免应用重启导致的 Ehcache 缓存数据丢失。 使用方法: 1. 在Jfinal(JFWebConfig.class)配置中添加全局拦截器,对方法进行过滤拦截 me.addGlobalServiceInterceptor(new J2CacheByMethodRegex("(.*get.*|.*find.*|.*list.*|.*search.*)", "(drop.*|.*update.*|.*delete.*)")); J2CacheByMethodRegex 有两个参数,第一个是使用缓存方法的表达式 .*get.*|.*find.*|.*list.*|.*search.* 其含义是:对所有含有get,find,list,search的关键字进行过滤,如果含有以上关键字,则使用J2Cache缓存数据返回值。如果没有命中关键字,则直接返回。 注意:关键字大小写敏感。 2. 在使用缓存前,要在对象上Duang一下 没错,就是Duang.Duang(具有关键字方法的对象),例如要查询活动时使用缓存,则在Model Activity里的dao上: public static final Activity dao = Duang.duang(new Activity()); 这样所有通过dao来操作的方法会被表达式过滤。get,find,list,search都会被缓存方法调用。 注意:想要用缓存一定要Duang.duang() 一定要Duang.duang() 一定要Duang.duang()。重要的事情说三遍。 还有另一种方法显示直接配置缓存。如果我的方法名不在默认表达式列表里,那么我怎么添加这个方法使用缓存呢? Jfianl提供了@Before 注解,我们利用@Before(J2CacheInterceptor.class) 放在方法名上就可以实现缓存的配置。但是对象的Duang还是必须要加上的。 3.缓存的清除 语法: @Before({PacketValidator.class, **ClearCache.class**, Tx.class}) **@J2CacheName(Packet.class)** public void addProductPackage() { 以上粗体部分就是清除缓存所要添加的内容: ClearCache.class是用来添加缓存的清除的拦截器定义。 关键:@J2CacheName(Packet.class)是指定了对应要清除的缓存类型。 三. Session 集群同步 页面历史 在集群环境下Session的同步是必须要解决的一个问题。用户登录了一台服务器,切换到另一台时,由Session保存用户登录信息。那么也就必须解决复制Session数据。 通常的解决方案都会考虑广播方式或者类似Terracotta 集群的解决方案。 考虑到系统中已有J2Cache已经包含了以上的两种同步方案,那么只需集成到项目即可。 必要条件**Shiro**,Shiro作为Filter已经在web 容器启动时实现并替换了容器的HttpSession,基于这个集成,我们只需将缓存和Shiro集成即可。 #cache shiroCacheManager = com.jfinalshop.security.J2CacheManager securityManager.cacheManager = $shiroCacheManager #session sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO EnterpriseCacheSessionDAO 会从J2CacheManager中获取缓存的session数据 四.weixin https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE&connect_redirect=1#wechat_redirect https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4444b1e3684a3615&redirect_uri=http%3A%2F%2Fdemo.mall.hupu.com%3A8080%2Fweixin%2Fmall&response_type=code&scope=snsapi_base&state=demo&connect_redirect=1#wechat_redirect https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4444b1e3684a3615&redirect_uri=http%3A%2F%2Fdemo.mall.hupu.com%2Fweixin%2Fmall&response_type=code&scope=snsapi_userinfo&state=demo&connect_redirect=1#wechat_redirect 五.JimStoneAjax 必须使用-parameters编译 手动引入js