当我添加“ Spring Boot Web Starter”时,默认情况下在Spring Boot中使用哪种视图技术。 如果要使用JSP,则需要为百里香叶模板包括'tomcat-embed-jasper'或'Spring Boot Thymeleaf Starter'。所以我想知道'Spring Boot Web Starter'的默认视图技术
答案 0 :(得分:1)
默认情况下没有视图,您需要配置并添加它们的依赖关系。如果您使用的是Spring Boot的旧版本,则可以参考上面的答案,但是如果您使用的是Spring Boot 2,则可以为thymeleaf添加更多的依赖关系->
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
答案 1 :(得分:0)
JSP
。
可以这样配置
@EnableWebMvc
@Configuration
public class ApplicationConfiguration implements WebMvcConfigurer {
@Bean
public ViewResolver jspViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/WEB-INF/views/");
bean.setSuffix(".jsp");
return bean;
}
}
或在属性文件中
spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp
对于Thymeleaf
Spring Boot将为pom.xml中具有以下依赖性的Thymeleaf
提供自动配置
请记下使用的版本。另外,您可能需要提供如上所述的视图属性
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.6.RELEASE</version>
</dependency>