其他分享
首页 > 其他分享> > enjoy模板引擎

enjoy模板引擎

作者:互联网

<dependency>
	<groupId>com.jfinal</groupId>
	<artifactId>enjoy</artifactId>
	<version>5.0.0</version>
</dependency>
import com.jfinal.kit.Kv;
import com.jfinal.template.Engine;
import com.jfinal.template.Template;

import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.HashMap;

/**
 * enjoy 模板引擎
 *
 * @author JHL
 */
public class T {

    public static void main(String[] args) {
        // 语法地址:https://jfinal.com/doc/6-3
        Engine engine = Engine.use();

        engine.setDevMode(true);
        engine.setToClassPathSourceFactory();

        Template template = engine.getTemplate("index.html");

        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("name", "名字");
        Kv kv = Kv.by("key", objectObjectHashMap);

        // 字节流模式输出到 OutputStream
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        template.render(kv, baos);

        // 字符流模式输出到 StringWriter
        StringWriter sw = new StringWriter();
        template.render(kv, sw);

        // 直接输出到 String 变量
        String str = template.renderToString(kv);
        System.out.println(str);
    }
}

标签:enjoy,engine,StringWriter,引擎,template,jfinal,import,com,模板
来源: https://www.cnblogs.com/hhddd-1024/p/16654153.html