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 ;

  • 相关阅读:
    Java之CyclicBarrier使用
    HashMap,LinkedHashMap,TreeMap的区别
    阿里巴巴常考面试题及汇总答案
    HashTable, HashMap,TreeMap区别
    Java集合类详解
    java代码的几个utils,基本可以直接用
    adb控制手机屏幕滑动(批处理)
    在设备上启用 adb 调试,有一个小秘密
    python clickZan
    python控制鼠标键盘
  • 原文地址:https://www.cnblogs.com/zhangxj/p/9753148.html
Copyright © 2011-2022 走看看