Thymeleaf 无法查看除一页之外的任何内容

发布于 2025-01-14 23:33:57 字数 2486 浏览 1 评论 0原文

我所能做的就是查看index.html,但是当我尝试浏览adminLogin时,我看到的只是:

白标错误页面 此应用程序没有 /error 的显式映射,因此您将其视为后备。 出现意外错误(类型=未找到,状态=404)。

这是PortfolioApplication:

@SpringBootApplication
public class PortfolioApplication {

    public static void main(String[] args) {
        SpringApplication.run(PortfolioApplication.class, args);
    }


    @GetMapping("/")
    public String getMainPage() {
        return "index.html";
    }

    @GetMapping("/adminLogin")
    public String getAboutPage() {
        return "adminLogin.html";
    }

}

当我尝试从index.html调用另一个页面时,没有任何反应:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hotel_Management_java_project</title>
    <link rel="stylesheet" href="css/home.css">
</head>

<body>
<div class="home" id="home">
    <nav>
        <div class="logo">
            <a href="#">
                <h2>TourAgency</h2>
            </a>
        </div>
        <div class="header_content">
            <ul>
                <li><a href="#home">Главная</a></li>
                <div class="login">
                    <button class="loginbtn" id="loginbtn">Вход</button>
                    <div class="Login_content">
                        <a th:href="@{/adminLogin}">Вход для админа</a>
                        <a th:href="@{/employeelogin}">Вход для работника</a>
                        <a th:href="@{/userlogin}">Вход для пользователя</a>
                    </div>
                </div>
            </ul>
        </div>
    </nav>
</body>

</html>

UserController:

@RestController
@RequestMapping("/users")
public class UserController {
    
    @Autowired
    private UserRepository urepo;
    
    @RequestMapping("/")
    public String index() {
        return "index"; 
    }
    
    @RequestMapping("/userlogin")
    public String index1(Model model) {
        model.addAttribute("user", new User());
        return "userlogin";
    }

我试图将@Controller更改为@RestController,将我的主类放在上面等等,但我没有结果

All I can is viewing index.html, but when I am trying to surf to adminLogin for example all i see is:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Not Found, status=404).

here is PortfolioApplication:

@SpringBootApplication
public class PortfolioApplication {

    public static void main(String[] args) {
        SpringApplication.run(PortfolioApplication.class, args);
    }


    @GetMapping("/")
    public String getMainPage() {
        return "index.html";
    }

    @GetMapping("/adminLogin")
    public String getAboutPage() {
        return "adminLogin.html";
    }

}

when i am trying to call another pages from index.html nothing happens:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hotel_Management_java_project</title>
    <link rel="stylesheet" href="css/home.css">
</head>

<body>
<div class="home" id="home">
    <nav>
        <div class="logo">
            <a href="#">
                <h2>TourAgency</h2>
            </a>
        </div>
        <div class="header_content">
            <ul>
                <li><a href="#home">Главная</a></li>
                <div class="login">
                    <button class="loginbtn" id="loginbtn">Вход</button>
                    <div class="Login_content">
                        <a th:href="@{/adminLogin}">Вход для админа</a>
                        <a th:href="@{/employeelogin}">Вход для работника</a>
                        <a th:href="@{/userlogin}">Вход для пользователя</a>
                    </div>
                </div>
            </ul>
        </div>
    </nav>
</body>

</html>

UserController:

@RestController
@RequestMapping("/users")
public class UserController {
    
    @Autowired
    private UserRepository urepo;
    
    @RequestMapping("/")
    public String index() {
        return "index"; 
    }
    
    @RequestMapping("/userlogin")
    public String index1(Model model) {
        model.addAttribute("user", new User());
        return "userlogin";
    }

I was trying change @Controller to @RestController, putting my main class to up and so on, but i've got no result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文