2017-03-04 09:33

model.keep(attr...);//保留哪些
model.remove(attrs...);//删除哪些

2017-03-04 09:23

创建的me对象是静态得, 多线程对静态方法的访问,是交叉执行的.
而且 .dao(); 方法能保证 me对象 只会被用来查询使用, 所以就不会有操作成员变量的情况,

2017-02-27 14:36

以我的脾气: rm -rf * 2333333333

2017-02-11 19:35

您现在应该访问:
http://localhost:8080/jfinal_demo/bolg
才对的, 因为你加了项目名称前缀,

MyEclipse , 建议先 修改 你的 Tomcat 配置 :

如我的: (因为过滤的关系, 以下"<""\" 以 "" 包裹 )
文件: F:\apache-tomcat-7.0.56\conf\server.xml
从后往前找: "<"/Host">" 这个标签, 在它前面加入:(记得加 WebRoot )

"<"Context docBase="F:\workspace\jfinal_3.0\WebRoot" path="" reloadable="false"/">"
"<"反斜杠Host">"


然后 再回到你 的MyEclipse 启动  Tomcat 就好了,

2017-02-09 15:23

@zhaozhihong 你肯定没有 BaseXxx, fastjson 里面是裁了 getXxx,setXxx 的三个字符.... 所以它就能知道需要put 哪些东西

2017-02-09 15:17

@杜福忠 ps : 上面的方法依赖于 BaseBlog 也就是 JavaBean, 得有getXxx,setXxx

2017-02-09 15:09

@JFinal 老大,上面的使用方式 有不妥的地方吗?

2017-02-09 15:05

实践出真"汁"...

public static void main(String[] args) {
PropKit.use("a_little_config.txt");
DruidPlugin dp = DemoConfig.createDruidPlugin();
ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
arp.addMapping("blog", Blog.class);
// 与web环境唯一的不同是要手动调用一次相关插件的start()方法
dp.start();
arp.start();
// 通过上面简单的几行代码,即可立即开始使用
new Blog().set("title", "title1").set("content", "cxt text").save();
new Blog().set("title", "title2").set("content", "cxt text").save();

//--------------------------------------------------------------------
// ----- 使用 fastjson 互转
Blog blog = Blog.me.findById(1);

//----- 使用 JsonKit : 类 转 json
String blogJson = blog.toJson();

System.out.println("blogJson:\t" + blogJson);

//----- 使用 fastjson : json 转 类
Blog parseObject = JSONObject.parseObject(blogJson, Blog.class);

System.out.println("parseObject.toJson(): \t" + parseObject.toJson());

//---------------------------------------------------------------------

List blogByAll = Blog.me.queryByAll();

//----- 使用 JsonKit : 类集合 转 json集合
String blogByAllJson = JsonKit.toJson(blogByAll);
System.out.println("blogByAllJson: \t" + blogByAllJson);

//----- 使用 fastjson : json集合 转 类集合
List jsons = JSONArray.parseArray(blogByAllJson, Blog.class);

for (Blog parse : jsons) {
System.out.println("List for : \t" + parse.toJson());
}
}

2017-02-08 16:36

enhance(Order.class).dealOrder() 这样写只能在Controller中使用, 因为在Controller中已经有这个方法了,所以您的Controller 就继承了!
Controller源码1237行以后, 这样写到:
public T enhance(Class targetClass) {
return (T)Enhancer.enhance(targetClass);
}


在任意的位置是这样调用的:
Enhancer.enhance(Order.class).dealOrder()


如手册第 4.6 Duang 、Enhancer 章的 例子:
public class TestMain{
public void main(String[] args) {
// 使用Duang.duang方法在任何地方对目标进行增强
OrderService service = Duang.duang(OrderService.class);
// 调用payment方法时将会触发拦截器
service.payment(…);
// 使用Enhancer.enhance方法在任何地方对目标进行增强
OrderService service = Enhancer.enhance(OrderService.class);
}
}

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