Java football-data.orgを利用して2017-2018シーズンのマンチェスター・シティの試合結果を取得する
Spring Bootを利用して何かWebアプリを作ろうと思い、色々考えてたところ「football-data.org」なるAPIを発見した。
こいつを使ってSpring BootとThymeleafのお勉強を兼ねたアプリを作ってみようと思う。
下記参考にさせてもらったブログです。
簡単!Spring BootでWebAPIをたたいてJSON形式のレスポンスをjavaオブジェクトに変換
jQueryで海外サッカーの試合結果を取得してみる – iBitzEdge
基本的には「football-data.org」から取得したjsonをpojoオブジェクトにセットしてThymeleafで画面表示しているだけです。
とりあえずThymeleaf部分だけ
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Get Football Data</title> </head> <body> <h1>マンチェスター・シティFCの試合結果</h1> <p>2017-2018シーズンの試合結果を表示します。</p> <div style="margin-top:8px" th:each="teamsFixtures: ${TeamsFixturesDto.fixtures}"> <p th:text="${teamsFixtures.date}"></p> <table border="1" style="width:500px;table-layout:fixed"> <tbody> <tr> <td style="text-align:center;background: lightblue;" th:text="${teamsFixtures.homeTeamName}"></td> <td style="text-align:center;background: lightblue;" th:text="${teamsFixtures.awayTeamName}"></td> </tr> <tr> <td colspan="2" style="text-align:center" th:text="${teamsFixtures.result.goalsHomeTeam + ' - ' + teamsFixtures.result.goalsAwayTeam }"></td> </tr> </tbody> </table> </div> <div class="matchresults-end"></div> </body> </html>
ソースコードはGitHubに上げました。 GitHub - tevez19911212/AddStringBuilder
これからチームの検索機能等を追加していく予定。
最終的にAWSとか使って公開できたらな~という感じです。