zoukankan      html  css  js  c++  java
  • 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 ;

  • 相关阅读:
    mysql 格林威治时间
    设置Highcharts刻度间距
    在PHP中判断单个字符是不是中文字符
    将ip以整形数据存储在数据库中的相关操作
    【Demo 0016】Windows 基本数据结构
    【Demo 0019】编码转换
    【Demo 0018】文字编码
    【Demo 0014】图形对象路径
    【Demo 0010】绘图对象区域
    【Demo 0017】Win32 基本结构体(1)
  • 原文地址:https://www.cnblogs.com/zhangxj/p/9753148.html
Copyright © 2011-2022 走看看