2017-02-08 09:57
性能不是 jfinal template engine 第一个版本的主要目标,第一版本的主要目标是极简,
性能后续会优化,如果后续在性能优化过程中过于牺牲架构与代码质量,则拒绝优化,性能比 velocity 与 freemarker 快很多以后,性能不是重点,
jfinal template engine 目前未做过任何优化,第一个版本的性能已然超过 velocity 与 freemarker,你可以想象一下后续的性能提升空间有多大,
为啥未做任何优化,并且第一个版本的性能这么好,这全是“极简”设计带来的红利,
因为,通常优雅的设计,天然拥有高性能,
而优化这件事,还要有个度,有些优化会让代码变得“dirty” 或者 "ugly",对于这种方式的优化,jfinal template engine 基本都会拒绝,
对于在当前性能的基础之上,再提升一点不必要的性能,去牺牲架构与代码质量,这是不值得的,
jfinal template engine 在后续去优化性能会把握这个度,
大家如果有兴趣,可以看一下 jfinal template engine 这部分的代码,再与其它模板引擎对比一下,立即会有所感觉,
jfinal template engine 的代码量只有 freemarker 的 10 分之 1, 只有 5000 多行,而 FM 有五万多行,对比一下源代码,去看,看一下哪个源码你可以看懂.
jfinal club 是我操刀,大家提供了很多反馈,才让 jfinal 越来越好,再加上现在俱乐部大家提供的资源,以后会更好
---- 摘自 俱乐部
2017-02-08 09:31
@杜福忠
ps:
@Before(Tx.class)
public void trans_demo() {// 这是 Controller 的一个 Action
//.... 这里面不能 try { } catch (){} 给吃掉, 如果业务需要,那就catch 捕获到以后需要再向上抛 throw,
}
比如写API的时候,就算异常了也要给调用者返回错误信息,不能是500吧,
我一般这样写:
// 这是 Controller 的一个 Action
//在前面加多个拦截器 参考手册第4.2 Interceptor 章节
@Before({renderJsonTxInterceptor.class, Tx.class})
public void trans_demo() {
//...
}
//这是 拦截器 renderJsonTxInterceptor的代码:
public class renderJsonTxInterceptor implements Interceptor {
@Override
public void intercept(Invocation inv) {
try {
//这里 测试就使用 System.out.println 了 生成是不能用的,会被打死
System.out.println("renderJsonTxInterceptor 进入");
inv.invoke();
System.out.println("renderJsonTxInterceptor 没有检查到异常");
} catch (Exception e) {
e.printStackTrace();
System.out.println("renderJsonTxInterceptor 捕获到异常,并放入错误码");
inv.getController().renderJson("{\"ret\":0}");//错误码自己定义,这里就不写了
}
}
}
2017-02-08 09:16
请打开手册第 : 5.5 声明式事务 章节
注意:MySql 数据库表必须设置为 InnoDB 引擎时才支持事务,MyISAM 并不支持事务。
最简单的方式:
在 Controller 的 Action 上面加@Before(Tx.class) ,
(ps:不能在其他类直接加 @Before(Tx.class), 如果需要使用, 具体使用方式参考 手册第4.6 Duang 、Enhancer 章节
如手册例:
@Before(Tx.class)
public void trans_demo() {// 这是 Controller 的一个 Action
//....
}
其他使用方式细读手册 :)
拦截器的配置方法见 Interceptor 有关章节 章节
2017-02-06 10:47
源码中这样写到:
//2.0 这样的__________________________________________
public FileRender(File file) {
this.file = file;
}
public FileRender(String fileName) {
fileName = fileName.startsWith("/") ? webRootPath + fileName : fileDownloadPath + fileName;
this.file = new File(fileName);
}
//3.0 这样的__________________________________________
public FileRender(File file) {
if (file == null) {
throw new IllegalArgumentException("file can not be null.");
}
this.file = file;
}
public FileRender(String fileName) {
if (StrKit.isBlank(fileName)) {
throw new IllegalArgumentException("fileName can not be blank.");
}
String fullFileName;
fileName = fileName.trim();
if (fileName.startsWith("/") || fileName.startsWith("\\")) {
if (baseDownloadPath.equals("/")) {
fullFileName = fileName;
} else {
fullFileName = baseDownloadPath + fileName;
}
} else {
fullFileName = baseDownloadPath + File.separator + fileName;
}
this.file = new File(fullFileName);
}
2017-02-06 10:34
@杜福忠 ps: 不要put, 只remove就可以了, 源码中已经put了,
/**
* Find model by cache.
* @see #find(String, Object...)
* @param cacheName the cache name
* @param key the key used to get data from cache
* @return the list of Model
*/
public List findByCache(String cacheName, Object key, String sql, Object... paras) {
ICache cache = getConfig().getCache();
List result = cache.get(cacheName, key);
if (result == null) { // 这里
result = find(sql, paras);
cache.put(cacheName, key, result); // 这里
}
return result;
}