【问题标题】:Facing a problem that I can't reach my other .html file面临无法访问其他 .html 文件的问题
【发布时间】:2019-02-13 21:30:54
【问题描述】:

我是 spring 框架的新手,我想稍后也使用 thymeleaf。但是,现在我只想创建一个基本页面,我可以在其中直接从一个选项卡跳转到另一个选项卡。当我启动我的程序时,我可以留在“主页”页面,但如果我想从导航打开其他选项卡,我会收到错误消息。据我了解映射问题,但无法意识到问题出在哪里。

错误:

白标错误页面 此应用程序没有 /error 的显式映射,因此您将其视为后备。

来自控制器的代码:

package com.project.project.ui.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class WelcomeController {

    @RequestMapping("/home")
    public String welcome() {
        return "index";
    }

    @RequestMapping(value = "/aphoto", method = RequestMethod.GET)
    public String add() {
        return "prideti";
    }

}

index.html 中的代码

<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <title>Galerija</title>
</head>
<body>
    <!-- Navigacija -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="">Galerija</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="prideti.html">Prideti nauja nuotrauka <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item active">
                <a class="nav-link" href="#">Perziureti nuotrauku galerija <span class="sr-only">(current)</span></a>
            </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="search" placeholder="Ieskoti" aria-label="Search">
            <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Ieskoti</button>
        </form>
    </div>
</nav>



<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>

这是我想要访问的页面:

<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <title>Galerija</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>

【问题讨论】:

  • 只是为了简化我的问题,我只想通过我的网站页面跳转,但我不能

标签: java html spring thymeleaf


【解决方案1】:

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

错误意味着,您没有根据控制器映射的 html 文件,或者您没有将它们放置在项目中的正确位置。

如果您使用的是 SpringBoot,则需要在路径 ApplicationRoot/src/main/resources/templates/ 上创建 index.htmlprideti.html

【讨论】:

  • 其实他们在那里-_-。他们都在同一个文件夹中
  • 你能在这里分享项目树吗?
猜你喜欢
  • 2021-06-17
  • 2016-03-09
  • 1970-01-01
  • 2011-05-24
  • 2016-03-03
  • 2013-12-22
  • 2018-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多