jfinal-dreampie基于 jfinal 的开源框架库
jfinal-dreampie 是一个基于jfinal的开源框架库,主要集成或调优功能如下:
1.缓存维护更细粒度
@CacheNameRemove(name = AppConstants.DEFAULT_CACHENAME) @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) public @interface CacheNameRemove { String name(); String[] keys() default {}; } //根据key值来移除基于某个特定方法的缓存,而不是移除整个controller下的缓存 String controllerKey = ai.getControllerKey(); if (!ValidateUtils.me().isNullOrEmpty(removeCacheName)) { String keyPrefix = null; if (!ValidateUtils.me().isNullOrEmpty(removeCacheKeys)) { for (String removeKey : removeCacheKeys) { keyPrefix = controllerKey + SLASH + removeKey; removeByCacheKey(removeCacheName, keyPrefix); } } else { keyPrefix = controllerKey; removeByCacheKey(removeCacheName, keyPrefix); } }
2.增加Slf4jLogger实现,然日志配置能基于任何Slf4j下的log实现,如logback
public class Slf4jLogFactory implements ILoggerFactory
3.基础model实现,实现基础的常用的部分功能用于复用
public List<M> findAll() { return find(getSelectSql() + getExceptSelectSql()); } public List<M> findBy(String where, Object... paras) { return find(getSelectSql() + getExceptSelectSql() + getWhere(where), paras); } public List<M> findTopBy(int topNumber, String where, Object... paras) { return paginate(1, topNumber, getSelectSql(), getExceptSelectSql() + getWhere(where), paras).getList(); } public M findFirstBy(String where, Object... paras) { return findFirst(getSelectSql() + getExceptSelectSql() + getWhere(where), paras); } public Page<M> paginateAll(int pageNumber, int pageSize) { return paginate(pageNumber, pageSize, getSelectSql(), getExceptSelectSql()); } public Page<M> paginateBy(int pageNumber, int pageSize, String where, Object... paras) { return paginate(pageNumber, pageSize, getSelectSql(), getExceptSelectSql() + getWhere(where), paras); } public boolean updateAll(String set, Object... paras) { return Db.update(getUpdateSql() + getSet(set), paras) > 0; } public boolean updateBy(String set, String where, Object... paras) { return Db.update(getUpdateSql() + getSet(set) + getWhere(where), paras) > 0; } public boolean deleteAll() { return Db.update(getDeleteSql()) > 0; } public boolean deleteBy(String where, Object... paras) { return Db.update(getDeleteSql() + getWhere(where), paras) > 0; } public boolean dropAll() { return Db.update(getDropSql()) > 0; } public boolean dropBy(String where, Object... paras) { return Db.update(getDropSql() + getWhere(where), paras) > 0; }
4.akka异步执行框架
public class AkkaPlugin implements IPlugin Akka.system().scheduler().scheduleOnce(Duration.create(1000, TimeUnit.MILLISECONDS), new Runnable() { @Override public void run() { //do Something } }, Akka.system().dispatcher());
5.atmosphere chat demo
@ManagedService(path = "/im/{room: [a-zA-Z][a-zA-Z_0-9]*}") public class ChatRoom { }
6.coffeescript compiler plugin,编译coffeescript代码,并监控文件改动重新编译
public class CoffeeScriptPlugin implements IPlugin { }
7.Flyway 数据库自动脚本升级 Plugin,用于自动生成或升级数据库,避免不断使用数据库工具修改数据导致的版本问题
public class FlywayPlugin implements IPlugin { }
8.lesscss compiler plugin,编译less代码,并监控文件改动重新编译
public class LessCssPlugin implements IPlugin { }
9.mailer 邮件发送plugin,使用akka异步发送邮件
Akka.system().scheduler().scheduleOnce(Duration.create(1000, TimeUnit.MILLISECONDS), new Runnable() { @Override public void run() { MailerConf mailerConf = MailerPlugin.mailerConf; HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setCharset(mailerConf.getCharset()); htmlEmail.setSocketTimeout(mailerConf.getTimeout()); htmlEmail.setCharset(mailerConf.getEncode()); htmlEmail.setHostName(mailerConf.getHost()); if (!ValidateUtils.me().isNullOrEmpty(mailerConf.getSslport())) htmlEmail.setSslSmtpPort(mailerConf.getSslport()); if (!ValidateUtils.me().isNullOrEmpty(mailerConf.getPort())) htmlEmail.setSmtpPort(Integer.parseInt(mailerConf.getPort())); htmlEmail.setSSLOnConnect(mailerConf.isSsl()); htmlEmail.setStartTLSEnabled(mailerConf.isTls()); htmlEmail.setDebug(mailerConf.isDebug()); htmlEmail.setAuthenticator(new DefaultAuthenticator(mailerConf.getUser(), mailerConf.getPassword())); try { htmlEmail.setFrom(mailerConf.getFrom(), mailerConf.getName()); htmlEmail.setSubject(subject); htmlEmail.addTo(recipients); htmlEmail.setHtmlMsg(body); // set the alternative message htmlEmail.setTextMsg("Your email client does not support HTML messages"); if (!ValidateUtils.me().isNullOrEmpty(attachment)) htmlEmail.attach(attachment); htmlEmail.send(); } catch (EmailException e) { e.printStackTrace(); } } }, Akka.system().dispatcher());
10.自定义验证码,可以自定义使用字符或者数字,颜色和样式可以自调
public class PatchcaRender extends Render { private static final String CODE_CHAR = "0123456789"; }
11.QuartzPlugin使用quartz执行定时任务,参照部分网络实例,简易实现
QuartzFactory.me().startJobOnce(TimeUtils.me().toString(DateTime.now()), ++jobId, "stati", this.getClass().getSimpleName(), OrderDataJob.class, param);
12.shiro权限框架,基于数据库url配置过滤,验证码验证
//读取数据库权限只需实现该接口 public interface JdbcAuthzService { public Map<String, AuthzHandler> getJdbcAuthz(); }
13.shiro的freemarker标签库
<@shiro.hasPermission name="P_USER"> <li><a href="/admin/user">${i18n.getText("admin.user")}</a></li> </@shiro.hasPermission>
14.xss过滤的StringEscapeUtils过滤器实现
public class AttackHandler extends Handler { @Override public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) { request = new HttpServletRequestWrapper(request); nextHandler.handle(target, request, response, isHandled); } }
15.json数据请求时,返回的error信息使用json字符串
public class JsonErrorRenderFactory implements IErrorRenderFactory { public Render getRender(int errorCode, String view) { if (ThreadLocalUtil.isJson()) return new JsonErrorRender(errorCode, view); else return new ErrorRender(errorCode, view); } }
16.自动绑定多数据源的tablebind
AutoMultiSourceTableBindPlugin tableBindDefault = new AutoMultiSourceTableBindPlugin(druidDefault, SimpleNameStyles.LOWER); //让default数据源排除shop目录下的model,因为该目录的model属于custom数据源 tableBindDefault.addExcludePaths("cn.dreampie.function.shop"); AutoMultiSourceTableBindPlugin tableBindCustom = new AutoMultiSourceTableBindPlugin(druidCustom, SimpleNameStyles.LOWER); //让custom只扫描shop目录,注意当使用includepaths是只会扫描配置的路径,如果没有使用includepaths会扫描全路径 tableBindCustom.addIncludePaths("cn.dreampie.function.shop");
17.压缩请求数据的gzipFilter,可测试
<!--gzip compress filter--> <filter> <filter-name>gzipFilter</filter-name> <filter-class>cn.dreampie.common.web.filter.gzip.GZIPFilter</filter-class> </filter> <filter-mapping> <filter-name>gzipFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> <!--gzip compress filter-->
18.http缓存cacheFilter,和gzipFilter共同用于提高用户性能
<!-- cache filter--> <filter> <filter-name>cacheFilter</filter-name> <filter-class>cn.dreampie.common.web.filter.cache.CacheFilter</filter-class> </filter> <filter-mapping> <filter-name>cacheFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> <!--cache filter-->
评论