#Jfinal2.0新特性初探 Jfinal2.0發佈了,我認爲這個是里程碑式的發佈,新加了很多好功能,這個博文主要是寫個那些不想看文檔,又想知道Jfinal2.0到底有什麼新變更的同窗們的,但願大家看完之後,會更加認識Jfinalweb
####只要攔截器作的好,沒有AOP幹不倒 ##Interceptor重現江湖 ###Interceptor細微變化1redis
public class DemoInterceptor implements Interceptor { public void intercept(Invocation inv) { System.out.println("Before method invoking"); inv.invoke(); System.out.println("After method invoking"); } }public class DemoInterceptor implements Interceptor { public void intercept(Invocation inv) { System.out.println("Before method invoking"); inv.invoke(); System.out.println("After method invoking"); } }
####只要攔截器作的好,沒有AOP幹不倒 ##Interceptor重現江湖 ###Interceptor細微變化1 public class DemoInterceptor implements Interceptor { public void intercept(Invocation inv) { System.out.println("Before method invoking"); inv.invoke(); System.out.println("After method invoking"); } }緩存
###Interceptor細分,引入InjectIntercept新成員app
###ClearInterceptor正式改名爲Clear工具
###AOP細分測試
// 定義須要使用AOP的業務層類 public class OrderService { // 配置事務攔截器 @Before(Tx.class) public void payment(int orderId, int userId) { // service code here } } // 定義控制器,控制器提供了enhance系列方法可對目標進行AOP加強 public class OrderController extends Controller { public void payment() { // 使用 enhance方法對業務層進行加強,使用具備AOP能力 OrderService service = enhance(OrderService.class); // 調用payment方法時將會觸發攔截器 service.payment(getParaToInt("orderId"), getParaToInt("userId")); } }
##有DUANG,DUANG特效才叫這酸爽ui
####一位新成員 Enhancer 工具類(DUANG)插件
####又一位新成員 Inject攔截器(DUANG)code
public void injectDemo() { // 爲enhance方法傳入的攔截器稱爲Inject攔截器,下面代碼中的Tx稱爲Inject攔截器 OrderService service = Enhancer.enhance(OrderService.class, Tx.class ); service.payment(…); }
第二個參數 Tx.class 被稱之爲 Inject 攔截器,使用此 方法即可徹底無侵入地對目標進行 AOP 加強視頻
Enhancer+Inject攔截器 ,今後世界上多了一門功夫,叫DUANGDUANG特效 ###多數據源支持(這個在1.9裏就有了)
詳細配置,參看文檔吧,切換數據源什麼的都很方便,直接經過db.use("dataSource").find(...)便可使用不一樣數據源中的數據
###非WEB環境裏使用ActiveRecord(這個很重要)
###非WEB環境裏使用ActiveRecord(這個很重要)
public class ActiveRecordTest { public static void main(String[] args) { DruidPlugin dp = new DruidPlugin("localhost", "userName", "password"); ActiveRecordPlugin arp = new ActiveRecordPlugin(dp); arp.addMapping("blog", Blog.class); // 與web環境惟一的不一樣是要手動調用一次相關插件的start()方法 dp.start(); arp.start(); // 經過上面簡單的幾行代碼,便可當即開始使用 new Blog().set("title", "title").set("content", "cxt text").save(); Blog.me.findById(123); } }
####非web 環境用 使用 RedisPlugin,寫各類測試用例,這個據對OK的
public class RedisTest { public static void main(String[] args) { RedisPlugin rp = new RedisPlugin("myRedis", "localhost"); // 與web下惟一區別是須要這裏調用一次start()方法 rp.start(); Redis.use().set("key", "value"); Redis.use().get("key"); } }
###國際化支持 是中國的 纔是世界的(使用方法見文檔,不想太多解釋了)
###新特性初探,就是這樣,等明白這個之後,你們能夠看看新特性的試用場景,後續視頻教程也會更上(前提是,有時間...,木有時間,無限期延後)