想问一下依赖注入倒底有啥好处?另外,多个变量怎么办?

public class DatiController extends BaseController {
    @Inject
    Psy psy;
    public void todati() {
        String psyid = getPara("psy.id");
        psy.setId(psyid);
        List<Record> psyById = psy.getById();
        renderJson(psyById);
    }
    


    public void todati2(){
        Psy psy = getModel(Psy.class, "psy");
        List<Record> records = psy.getById();
        renderJson(records);
    }
}

上边是新写法,下边是老写法

看不出来有啥好处呢??

评论区

杜福忠

2018-11-29 18:24

... 用错了...
http://www.jfinal.com/doc/4-5

http://www.jfinal.com/doc/4-1

杜福忠

2018-11-29 23:23

https://gitee.com/-/ide/project/jfinal/jfinal/edit/master/-/src/main/java/com/jfinal/aop/Aop.java