springboot2解析不了网页的解决

新建了一个springboot2的框架。

建立了控制器:

package cn.jhxcom.web.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class TestViewController {


  @GetMapping(value="/index")
   public String Index(){
   return "index";
   }

}

在没有创建自定义的拦截器, 启动应用后,在浏览器输入:http:/localhost:8080 后,是可以解析/src/main/resources/static/目录下index.html 。

建立拦截器后,系统报错:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Oct 08 11:10:01 CST 2018
There was an unexpected error (type=Internal Server Error, status=500).
Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

意思就是不能解析view。在pom.xml文件里增加依赖:

             <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-thymeleaf</artifactId>

              </dependency>

 

运行应用,在浏览器输入:http:/localhost:8080/index

系统解析了/src/main/resources/templates/index.html,并在浏览器正常显示。

 

总结:

1.在没有增加用户的拦截器时,浏览器输入:http:/localhost:8080 ,系统自动访问:/src/main/resources/static/目录下的index.html ;

   http:/localhost:8080/index 时访问/src/main/resources/templates/目录下的index.html ;

2.在增加用户的拦截器时,浏览器输入: http:/localhost:8080/ 系统找不到网页,

   http:/localhost:8080/index时,访问/src/main/resources/templates/目录下的index.html ;

 

posted @ 2018-10-08 11:01  孤独的战斗笋  阅读(1330)  评论(0编辑  收藏  举报