質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

0回答

586閲覧

Spring DB取得結果 画面表示 Whitelabel Error Pageが解決したい

munewaki

総合スコア0

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2022/05/27 06:24

スプリングフレームワークを使用してDBから取得した値を画面上に表示しようと試みているのですがWhitelabel Error Page となってうまく表示されません。
ステータスは500となっています。解決方法を調べたのですがうまくいかないためご助力いただきたいです

以下はエラー内容となります

022-05-27 14:54:34.035 ERROR 16228 --- [nio-8180-exec-6] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8180-exec-6] Exception processing template "user/list": Exception evaluating SpringEL expression: "ID" (template: "user/list" - line 19, col 15) org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "ID" (template: "user/list" - line 19, col 15) at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:292) ~[thymeleaf-spring5-3.0.15.RELEASE.jar:3.0.15.RELEASE] Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'ID' cannot be found on object of type 'com.example.entity.User' - maybe not public or not valid? 2022-05-27 14:54:34.043 ERROR 16228 --- [nio-8180-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "ID" (template: "user/list" - line 19, col 15)] with root cause org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'ID' cannot be found on object of type 'com.example.entity.User' - maybe not public or not valid?

以下ソースコードです

controllerクラス

package com.example.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import com.example.entity.User; import com.example.service.UserService; @Controller public class DBgetValue { /** * ユーザー情報 Service */ @Autowired private UserService userService; /** * ユーザー情報一覧画面を表示 * @param model Model * @return ユーザー情報一覧画面 */ @GetMapping(value = "/user/list") public String displayList(Model model) { List<User> userlist = userService.searchAll();//userServiceクラスのメソッドを呼び出している model.addAttribute("userlist", userlist);//サービスクラスから取得した内容を設定している return "user/list";//表示する画面を設定している(model.addAttributeで画面に渡す情報を指定してこの画面を表示する) } }

サービスクラス

package com.example.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.example.entity.User; import com.example.repository.UserRepository; /** * ユーザー情報 Service */ @Service public class UserService { /** * ユーザー情報 Repository */ @Autowired private UserRepository userRepository; /** * ユーザー情報 全検索 * @return 検索結果 */ public List<User> searchAll() { return userRepository.findAll();//データベースから全件取得してくるのでリポジトリクラスに設定されているfindAllメソッドを呼び出してリターン //findAllでエンティティに詰めて返却している } }

エンティティクラス

package com.example.entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; /** * ユーザー情報 Entity */ @Entity // ここでエンティティクラスだと明示している @Table(name = "DBSAMPLE") // SELECT対象のテーブル名を記載 public class User { @Id @Column(name = "ID")//DB上のどのカラムなのかを記載 @GeneratedValue(strategy = GenerationType.IDENTITY) private String ID; @Column(name = "NAME") private String NAME; @Column(name = "SEX") private String SEX; public String getID() { return ID; } public void setID(String iD) { ID = iD; } public String getNAME() { return NAME; } public void setNAME(String nAME) { NAME = nAME; } public String getSEX() { return SEX; } public void setSEX(String sEX) { SEX = sEX; } }

リポジトリクラス

package com.example.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import com.example.entity.User; /** * ユーザー情報 Repository */ @Repository public interface UserRepository extends JpaRepository<User, String> { //ここの親クラスにfindAllメソッドが存在しているので全件取得することができる }

画面HTML

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head th:replace="common/head :: head_fragment(title = 'ユーザー情報一覧', scripts = ~{::script}, links = ~{::link})"></head> <body> <div class="container"> <h1>ユーザー情報一覧</h1> </div> <table border="1"> <thead> <tr> <th>ID</th> <th>名前</th> <th>性別</th> <th></th> </tr> </thead> <tbody> <tr th:each="user : ${userlist}" th:object="${user}" class="align-middle"> <td th:text="*{iD}"></td> <td th:text="*{nAME}"></td> <td th:text="*{sEX}"></td> </tr> </tbody> </table> </div> </body> </html>

以上となります。
宜しくお願いします

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2022/05/27 06:52

エラーに原因書いてありますが、そちらについては認識済みですか?
munewaki

2022/05/27 07:21 編集

ご回答ありがとうございます。 その原因があまり理解できていないため解決できておりません。 根本的な原因がID" (テンプレート: "user/list" - 19行目、15列目)であるといったことしかわからず 解決にいてっていない状態です
m.ts10806

2022/05/27 07:44 編集

>Property or field 'ID' cannot be found on object of type 'com.example.entity.User' ['com.example.entity.User']にはIDというフィールドはない という意味です。 ビュー(HTML)には iD とか書いてあるのでそのあたりじゃないでしょうか。 他の項目もですね。 大文字小文字は大別されます。
munewaki

2022/05/27 07:47

この箇所をIDとしてもiDとしていてもエラー内容が変わらないため、どのようにしていいのかわからない状態になっております。
dewa

2022/06/03 16:03 編集

エラー発生時点のコードと、記載されているコードが一致していないと思われます (そのため原因が特定できません)。 記載されているコードでエラーが発生したのであれば、 ``` Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "" (template: "user/list" - line 19, col 15) ``` となるはずです ("iD"となるはずですが、質問文中のエラーメッセージは "ID" となっている)。 ---- 今回のエラーと直接関係あるか分かりませんが、 @GeneratedValue 付与するidフィールドを String 型にするのは誤りで、数値型(典型的には Long)にすべきです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問