#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"); } }
###国际化支持 是中国的 才是世界的(使用方法见文档,不想太多解释了)
###新特性初探,就是这样,等明白这个之后,你们能够看看新特性的试用场景,后续视频教程也会更上(前提是,有时间...,木有时间,无限期延后)