Spring前端Controller项目替换为SpringBoot遇到的坑

页面解析不了加入如下配置:

pom:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
    <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>
</properties>

页面需要放在resources的templates目录下,其他静态文件放在resources目录下

配置文件:
#######################thymeleaf################################
server.servlet.context-path=/aiis //替换成自己的项目路径
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix= .html
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode: HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false
#######################静态资源处理################################
spring.resources.static-locations=classpath:/static/,classpath:/META-INF/resources/,classpath:/resources/,classpath:/public/,classpath:/resources/static/
spring.mvc.static-path-pattern=/static/**
加入配置类:
@SpringBootConfiguration
public class WebMvcConfig extends WebMvcConfigurationSupport {
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
      super.addResourceHandlers(registry);
   }
}

猜你喜欢

转载自blog.csdn.net/yht874690625/article/details/87877831