2017-03-14 16:25
@Irin.Chan 是啊用了代码格式, 就不能画底色了, 所以我放弃了用代码格式, 用这个底色主要是划重点, 然后再去看源码会有轻松些
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: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);
}
}