首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Jade4J配置为Spring中的默认模板引擎

将Jade4J配置为Spring中的默认模板引擎
EN

Stack Overflow用户
提问于 2018-10-23 11:44:52
回答 2查看 576关注 0票数 0

我最近为我的大学Java课程项目选择了Spring框架,选择了Jade4J作为我的模板引擎,已经在pom.xml中安装了这个包,但是当我调用Jade4J.render("./index.jade", model);时,我得到了“./index.jj(没有找到文件)”响应。在github回购中,没有关于如何使用它将查找的模板的目录生成配置类的特定信息。我甚至尝试将index.jade文件放在项目的任何地方(控制器dir、实现main.java的dir、资源dir、webapp dir)。如果需要的话,我会提供任何进一步的信息,我将不胜感激。

编辑1

将JadeConfig类添加到具有以下内容的项目中:

代码语言:javascript
复制
@Bean
public SpringTemplateLoader templateLoader() {
    SpringTemplateLoader templateLoader = new SpringTemplateLoader();
    templateLoader.setBasePath("/templates/");
    templateLoader.setEncoding("UTF-8");
    templateLoader.setSuffix(".jade");
    return templateLoader;
}

@Bean
public JadeConfiguration jadeConfiguration() {
    JadeConfiguration configuration = new JadeConfiguration();
    configuration.setCaching(false);
    configuration.setTemplateLoader(templateLoader());
    return configuration;
}

@Bean
public ViewResolver viewResolver() {
    JadeViewResolver viewResolver = new JadeViewResolver();
    viewResolver.setConfiguration(jadeConfiguration());
    return viewResolver;
}

我的索引控制器具有以下功能:

代码语言:javascript
复制
@GetMapping(value = "/")
public String greeting() throws IOException {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("title", "Index Page");
    String html = Jade4J.render("./index.jade", model);
    return html;
}

最后,模板index.jade路径是src\main\webapp\templates\index.jade。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-23 12:05:21

您查看了Jade4j https://github.com/neuland/spring-jade4j的Spring集成吗?

它详细介绍了如何使用Spring配置Jade4j。

代码语言:javascript
复制
<bean id="templateLoader" class="de.neuland.jade4j.spring.template.SpringTemplateLoader">
    <property name="basePath" value="/WEB-INF/views/" />
</bean>

<bean id="jadeConfiguration" class="de.neuland.jade4j.JadeConfiguration">
    <property name="prettyPrint" value="false" />
    <property name="caching" value="false" />
    <property name="templateLoader" ref="templateLoader" />
</bean>

<bean id="viewResolver" class="de.neuland.jade4j.spring.view.JadeViewResolver">
    <property name="configuration" ref="jadeConfiguration" />
    <!-- rendering nice html formatted error pages for development -->
    <property name="renderExceptions" value="true" />
</bean>
票数 0
EN

Stack Overflow用户

发布于 2019-05-24 16:05:58

对于那些试图寻找Jade4j信息的新人来说。

在这里,您可以找到没有错误的示例和模板引擎https://github.com/jreijn/spring-comparing-template-engines的其他示例。

主要的问题是你真的需要Jade4j吗?

上一次发布是2017年,他没有一个大型的社区https://mvnrepository.com/artifact/de.neuland-bfi/jade4j

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52948233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档