spring-boot配置thymeleaf实现html界面跳转

不得不说配置真的是烦,最近由于有个需求是上传图片到本地磁盘,然后url字段保存在数据库当中,于是乎就用了下spring-boot,下面就简单的整理下遇到的坑

首先我们需要去配置spring-boot-starter-thymeleaf的时候,如果我们用的是 Spring Boot 2.0.2的话是会报错了,而且是一大堆错,所以这里建议将2.0.2改成使用1.5.10,所以我们在pom.xml文件当中我们应该这么写

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

如果pom.xml当中还有其他的依赖包,我们可以都先删除,先将1.5.10的spring-boot给集成过来然后我们再去导入其他的依赖包,下面是我下的几个依赖包

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!-- MYSQL -->
         <!-- Spring Boot JDBC -->

          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
          </dependency>

          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
          </dependency>


          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
          </dependency>
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
          </dependency>


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

<dependency>   
<groupId>net.sourceforge.nekohtml</groupId>   
<artifactId>nekohtml</artifactId>   
<version>1.9.22</version>   
</dependency> 

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> 

</dependencies>

然后我们把我们要跳转的静态界面一般是放在src/main/resources/templates下的,在这里我们可以放入我们自己写的html界面

特别需要注意的,如果要实现界面的跳转一定要在application.properties中添加下面两行,否则无法跳转会报500错误

spring.mvc.view.prefix=classpath:/templates/

spring.mvc.view.suffix=.html

猜你喜欢

转载自blog.csdn.net/zcmuczx/article/details/80693631
今日推荐