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 11:29

这条完美解决了我当前代码冗余的问题:
20:Model.getConfig() 的可见性由 private 改为 protected

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;
}

2017-02-06 10:28

remove 比 put 好一点, 比如 可以起到懒加载的作用 省点内存

2017-01-18 23:04

传送门:http://www.jfinal.com/share/73 海哥精辟详解

2017-01-13 19:11

mysql手册:

一个名为FIND_IN_SET的函数 , 就是设计用来处理这种以 逗号 分割做关系的.

如:
SELECT * FROM massage_js_pending_info
WHERE yn = 1 AND FIND_IN_SET(actionStatus, ? ) AND ...

如果你的 actionStatus 比较多
还可以使用: MATCH AGAINST

度娘一下就知道了

2017-01-04 16:25

@david wang 老大?这能 a ?

2016-12-28 09:03

http://www.kafeitu.me/activiti/2012/03/22/workflow-activiti-action.html

2016-12-24 09:43

public class BaseController extends Controller {

/**获取访问者域名*/
public String getWebSite(){
return getRequest().getServerName();
}

}
我是这样做的,不知道有什么弊端没有

2016-11-25 09:12

这个项目里面有个小工具:

http://www.jfinal.com/project/16

文件位置:
/JFinalUIBV3/platform/com/platform/tools/ToolPoi.java