Springboot 統合 thymeleaf は、このアプリケーションには /error の明示的なマッピングがないことを報告するため、これはフォールバックとして表示されます。このアプリケーションには /err の明示的なマッピングがありません

研究中、タイムリーフの使用中に生じる問題

データベースはアカウントで、フィールドはアカウントエイド、アカウント残高、ユーザー番号uidです。

 コントローラー層アカウントコントローラー

@Controller
@RequestMapping("/acc")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @GetMapping("/ac")
    public String query(ModelMap modelMap){
        List<Account> accounts = accountService.accounts();
        modelMap.put("accounts",accounts);
        return "account-list";
    }
}

 account-list.html は src/main/resources/templates ファイルの下にあります

<!DOCTYPE html>
<html lang="en" xmlns="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css"  th:href="@{../css/style.css}"/>
    <script src="" th:src="@{../js/fu.js}"></script>
</head>
<body>
<img th:src="@{../images/wode.jpg}" class="wode"/>
<h1>用户列表展示</h1>
<table border="1">
    <tr>
        <th>序号</th>
        <th>账户编号</th>
        <th>账户余额</th>
        <th>用户编号</th>
    </tr>

    <tr th:each="account,iterStat:${accounts}">
        <td th:text="${iterStat.index+1}"></td>
        <td th:text=""></td>
        <td th:text="${account.aid}"></td>
        <td th:text="${account.money}"></td>
        <td th:text="${account.uid}"></td>
    </tr>
</table>
<hr/>
<br>
<button onclick="text()">点击测试</button>
</body>
</html>

 localhost:8092/acc/ac へのアクセスでエラーが発生したため、ポート番号を変更しました

 解決:

1. +@RestController を行わないように注意してください。そうしないと、以下で返されるのはページではなく文字列になります。

 2. Thymeleaf に厳密な文法がある、不完全なページ参照または文法上の問題がある、または値が書き込まれていない場合は、エラーが報告され、ページが表示されません。

3. ページの静的リソースが読み込まれない場合は、リソース導入パスの問題です

<script src="" th:src="@{../js/fu.js}"></script>

ファイル内でエラーが報告されている場所を確認し、この行を見つけます。22 行目に問題があり、null 値があることが示されています。 

 ここに null 値があります。null 値をコメントアウトします。

 完璧に機能します

 

おすすめ

転載: blog.csdn.net/zhenghaochang/article/details/129404811