Closed Ryoma137 closed 2 years ago
下記を参考に @queryをつけてqueryを生成する。 https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query
Unique index or primary key violation:
が発生、primary keyが重複しているのでテストを実行毎にsqlのデータが削除されていないことを確認。→ test-schema.sqlにTRUNCATE
文を追加し、実行のたびにデータを削除するようにsqlを変更。 return"expense";
とexpenseを返し、 @GetMappingで指定したURIに接続してもhtmlファイルが読み込まれず、expense
という文字のみ表示される。HTMLで返すためにIncomeControllerのアノテーションを@RestControllerではなく、@Controllerに変更。
すると、Cannot invoke "com.recordofexpense.recordofexpense.service.AmountService.getCategoryList()" because "this.amountService" is null
のエラーが発生。
実行時にDBにデータがinsertされるSQLファイルが必要なのかと思いsrc/main/resources下にsqlファイルを作成し、INSERT
文を記載。
その後実行すると、エラーログTable "AMOUNT" not found (this database is empty)
が表示される。(H2は組み込みのDBで実行時にDBが作成されるが、DBが作成する前にINSERTをしようとして table not found になっていると推測している)
@Ryoma137 また迷走しそうな感じです。ログをしっかりと読んで理解しましょう。
すると、Cannot invoke "com.recordofexpense.recordofexpense.service.AmountService.getCategoryList()" because "this.amountService" is nullのエラーが発生。
これは、単に(どこかの)amountService が null だよって言ってるだけなので、DB は関係ないです。 エラーログに表示されるスタックトレースを見ると、どこでエラーが発生しているのかわかるので、それをもとにエラー箇所を探りましょう
@AllArgsConstructorをつけてconstructorを生成。
すると、Circular view path [expense]: would dispatch back to the current handler URL [/expense] again
のエラーが発生。
→ pom.xml
に以下のdependencyを追加。
`
<artifactId>spring-boot-starter-thymeleaf</artifactId>
`
実行後、今度は Could not parse as each: "categoryList: ${categoryLists}}" (template: "expense" - line 27, col 23)
のエラーが発生。
Thymeleaf側でデータの表示機能で何かしらのエラーが発生、データの表示の仕方が間違っていると推測。
testGetCategory をactualのリストに 各カテゴリーの文字列が入っているテストに変更 着手開始
テストに記述された(getCategoryList の)仕様に合わせて、getCategoryListの実装を変更 done *push済
作成した画面にDBから取得したカテゴリーを表示(thymeleafの修正) 着手開始
DBから取得したデータをthymeleafで表示させるために以下のコードを追加。drop downリストは表示されるが、リスト内に値が何も入ってない。
<select name="category"> <option th:each="categoryList : ${categoryLists}" th:text = "${categoryList.category}"> </option>
作成した画面にDBから取得したカテゴリーを表示のテスト手順
マージ済