• 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 ;

  • 相关阅读:
    对流程和规范的思考
    我的一小时面试指南
    安全扫描工具nikto简单使用
    测试的角色
    测试的窘境
    关于重连测试的一点研究
    ETCD高可用特性学习
    Cgroup和Namespace在测试中的使用(下)
    单循环列表的删除前驱结点
    指针常量字符串
  • 原文地址:https://www.cnblogs.com/zhangxj/p/9753148.html
Copyright © 2020-2023  润新知