Springboot整合beetl模板的时候出现视图解析404问题,请求能够进入controller里面,但是返回到视图模板的时候出现404!配置如下:(刚使用springboot,求教高人指点迷津,关于springBoot的视图解析过程不了解,看了书上写得不是很详细。)
1:pom文件
<!-- 引入Springboot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<!-- 声明一个web应用 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 集成SpringMVC时引入视图模板beetl -->
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>2.5.3</version>
</dependency>
2:controller文件:
@Controller
public class HelloController {
@RequestMapping("/say.html")
public String say(Model model){
model.addAttribute("name", "hello,Springboot,nihao2hot");
System.out.println("do from say...");
return "/hello.btl";
}
3:resources下conf文件如下:
@Configuration
public class BeetlConf {
@Bean(initMethod = "init", name = "beetlConfig")
public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration() {
BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();
ResourcePatternResolver patternResolver = ResourcePatternUtils
.getResourcePatternResolver(new DefaultResourceLoader());
try {
WebAppResourceLoader cploder = new WebAppResourceLoader(patternResolver.getResource("/templates").getFile().getPath());
beetlGroupUtilConfiguration.setResourceLoader(cploder);
return beetlGroupUtilConfiguration;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
4:resources下templates下的模板文件为hello.btl