最後にViewを作って完成です。
Controllerの返り値として「bbs/index」を指定しているので、templatesディレクトリの中にbbsフォルダを作ってその中にindex.htmlを作成します。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head>     <meta charset="UTF-8" />     <title>BBS</title> </head> <body>     <h1>BBS</h1>     <ol>         <li th:each="comment:${commentList}"><span th:text="${comment.name}">名前</span>: <span th:text="${comment.text}">テキスト</span></li>     </ol>     <form th:action="@{/bbs/}" method="post">         <input type="text" name="name" />         <input type="text" name="text" /><input type="submit" />     </form> </body> </html> | 
- 10行目: th:eachを使うとリストから1つずつ取り出して、要素が生成される。この場合commentListから取り出した値はcommentとして参照できる。comment.nameでcomment.getName()が実行される。
- 12行目: actionの代わりにth:actionを指定すると@{}を使ってURLを記述することができる。@{}を使うと、contextに応じたpathに書き換えてくれる。
実行例

H2コンソールで確認すると、idが自動的に割り当てられているのがわかります。
