我最近为我的大学Java课程项目选择了Spring框架,选择了Jade4J作为我的模板引擎,已经在pom.xml中安装了这个包,但是当我调用Jade4J.render("./index.jade", model);时,我得到了“./index.jj(没有找到文件)”响应。在github回购中,没有关于如何使用它将查找的模板的目录生成配置类的特定信息。我甚至尝试将index.jade文件放在项目的任何地方(控制器dir、实现main.java的dir、资源dir、webapp dir)。如果需要的话,我会提供任何进一步的信息,我将不胜感激。
编辑1
将JadeConfig类添加到具有以下内容的项目中:
@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;
}我的索引控制器具有以下功能:
@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。
发布于 2018-10-23 12:05:21
您查看了Jade4j https://github.com/neuland/spring-jade4j的Spring集成吗?
它详细介绍了如何使用Spring配置Jade4j。
<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>发布于 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
https://stackoverflow.com/questions/52948233
复制相似问题