Ryoma137 / record-of-expense

0 stars 0 forks source link

(支出)drop downでカテゴリ一覧を表示 #2

Closed Ryoma137 closed 2 years ago

Ryoma137 commented 2 years ago
Ryoma137 commented 2 years ago

下記を参考に @queryをつけてqueryを生成する。 https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query

Ryoma137 commented 2 years ago
Ryoma137 commented 2 years ago
Ryoma137 commented 2 years ago

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 になっていると推測している)

t-ita commented 2 years ago

@Ryoma137 また迷走しそうな感じです。ログをしっかりと読んで理解しましょう。

すると、Cannot invoke "com.recordofexpense.recordofexpense.service.AmountService.getCategoryList()" because "this.amountService" is nullのエラーが発生。

これは、単に(どこかの)amountService が null だよって言ってるだけなので、DB は関係ないです。 エラーログに表示されるスタックトレースを見ると、どこでエラーが発生しているのかわかるので、それをもとにエラー箇所を探りましょう

Ryoma137 commented 2 years ago

@AllArgsConstructorをつけてconstructorを生成。 すると、Circular view path [expense]: would dispatch back to the current handler URL [/expense] againのエラーが発生。 → pom.xmlに以下のdependencyを追加。

`

org.springframework.boot
<artifactId>spring-boot-starter-thymeleaf</artifactId>

`

実行後、今度は Could not parse as each: "categoryList: ${categoryLists}}" (template: "expense" - line 27, col 23)のエラーが発生。 Thymeleaf側でデータの表示機能で何かしらのエラーが発生、データの表示の仕方が間違っていると推測。

Ryoma137 commented 2 years ago

testGetCategory をactualのリストに 各カテゴリーの文字列が入っているテストに変更 着手開始

Ryoma137 commented 2 years ago
Ryoma137 commented 2 years ago

テストに記述された(getCategoryList の)仕様に合わせて、getCategoryListの実装を変更 done *push済

Ryoma137 commented 2 years ago

作成した画面にDBから取得したカテゴリーを表示(thymeleafの修正) 着手開始

Ryoma137 commented 2 years ago

DBから取得したデータをthymeleafで表示させるために以下のコードを追加。drop downリストは表示されるが、リスト内に値が何も入ってない。

<select name="category"> <option th:each="categoryList : ${categoryLists}" th:text = "${categoryList.category}"> </option>

Ryoma137 commented 2 years ago

作成した画面にDBから取得したカテゴリーを表示のテスト手順

Ryoma137 commented 2 years ago

マージ済