简体   繁体   English

spring boot默认使用什么样的view技术

[英]What kind of view technology used in spring boot by default

What kind of view technology used in spring boot by default when I add the 'Spring Boot Web Starter'.我添加'Spring Boot Web Starter'时默认使用什么样的视图技术。 If I want to use the JSP, I need to include the 'tomcat-embed-jasper' or 'Spring Boot Thymeleaf Starter' for thymeleaf templates.如果我想使用 JSP,我需要为 thymeleaf 模板包含“tomcat-embed-jasper”或“Spring Boot Thymeleaf Starter”。 So I would like to know the default view technology of 'Spring Boot Web Starter'所以我想知道'Spring Boot Web Starter'的默认视图技术

By default there is no view You need to configure and add their dependencies.If You are using Spring Boot older versions then You can refer above answer but if You are using Spring Boot 2 then add on more dependency for thymeleaf-默认情况下没有视图您需要配置和添加它们的依赖项。如果您使用的是 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>

JSP is supported by Spring out-of-the-box. JSP由 Spring 开箱即用的支持。

It can be configured like this可以这样配置

@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;
    }
}

or in properties file或在属性文件中

spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp

For Thymeleaf百里香叶

Spring Boot will provide auto-configuration for Thymeleaf with below dependency in pom.xml Spring Boot 将为Thymeleaf提供自动配置,在 pom.xml 中具有以下依赖项

Please make a note of version used.请记下使用的版本。 Also you might need to provide view properties like above您还可能需要提供上述视图属性

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <version>1.5.6.RELEASE</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM