独立使用 Enjoy 渲染Record对象报错

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.template.Engine;

public class Main {
    public static void main(String[] args){
        Engine engine = Engine.use();
        engine.setDevMode(true);
        String s = engine.getTemplate("C:\\Users\\admin\\Desktop\\a\\index.html").renderToString(Kv.by("r",new Record().set("k","v")));
        System.out.println(s);
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
#(r.k)
</body>
</html>

Exception in thread "main" com.jfinal.template.TemplateException: public field not found: "r.k" and public getter method not found: "r.getK()"

Template: "/C:\Users\admin\Desktop\a\index.html". Line: 8

at com.jfinal.template.expr.ast.Field.eval(Field.java:88)

at com.jfinal.template.stat.ast.Output.exec(Output.java:49)

at com.jfinal.template.stat.ast.StatList.exec(StatList.java:68)

at com.jfinal.template.Template.render(Template.java:74)

at com.jfinal.template.Template.renderToString(Template.java:91)

at com.quick.Main.main(Main.java:12)


评论区

杜福忠

2021-07-14 16:12

升级最新版本,或者改为 #(r.get('k'))

jm80

2021-07-14 16:19

@杜福忠 波总已经给我详细解答了 使用activerecord独立版就可以了包含了 enjoy

chcode

2021-07-14 17:04

@jm80 你现在才知道啊