我是spring框架的新手,以后也想使用百里香。但是,现在,我只想创建一个基本页面,在其中可以直接从一个选项卡跳转到另一个选项卡。当我启动程序时,我可以停留在“主页”页面,但是如果我想从导航中打开其他选项卡,则会收到错误消息。据我了解映射问题,但无法意识到问题出在哪里。
错误:
Whitelabel错误页面 此应用程序没有针对/ 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>
答案 0 :(得分:0)
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
错误意味着,根据控制器的映射,您没有html文件,或者没有将它们放在项目中的正确位置。
如果您使用的是SpringBoot,则需要在路径index.html
上创建prideti.html
和ApplicationRoot/src/main/resources/templates/
。