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

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

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

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

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Thymeleaf

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

Q&A

2回答

4399閲覧

画面表示したいが、whitelabel errorと表示されてしまう

NakkaFive

総合スコア2

Java

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

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Thymeleaf

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

0グッド

1クリップ

投稿2020/10/21 11:07

編集2020/10/21 13:28

前提・実現したいこと

Javaで検索と削除機能付きシステムを作っています。
実行して、http://localhost:8080/にアクセスしてたところ
以下のページが出てしまいました。
コンソール上のエラーが出ていないので、対応が分かりません。

ご教示いただけますと幸いです。

発生している問題・エラーメッセージ

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Wed Oct 21 15:40:16 JST 2020 There was an unexpected error (type=Not Found, status=404).

該当のソースコード

java

1package com.example.demo; 2 3import org.springframework.boot.SpringApplication; 4import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6@SpringBootApplication 7public class ShainListApplication { 8 9 public static void main(String[] args) { 10 SpringApplication.run(ShainListApplication.class, args); 11 } 12 13} 14 15
package com.example.demo; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import lombok.Data; /** * 社員情報 Entity */ @Entity @Data @Table(name="employee") public class User implements Serializable { /** * 社員情報 */ @Id @Column(name="id") @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; /** * 名前 */ @Column(name="name") private String name; /** * 生年月日 */ @Column(name="birthday") private String birthday; /** * 住所 */ @Column(name="address") private String address; /** * 電話番号 */ @Column(name="phone") private String phone; /** * 部門 */ @Column(name="department") private String department; }
import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.ObjectError; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * 社員情報 Controller */ @Controller public class UserController { /** * 社員情報 Service */ @Autowired UserService userService; /** * 社員情報一覧画面を表示 * @param model Model * @return 社員情報一覧画面 */ @RequestMapping(value = "/user/list", method = RequestMethod.GET) public String displayList(Model model) { List<User> userlist = userService.searchAll(); model.addAttribute("userlist", userlist); return "user/list"; } /** * 社員新規登録画面を表示 * @param model Model * @return 社員情報一覧画面 */ @RequestMapping(value = "/user/add", method = RequestMethod.GET) public String displayAdd(Model model) { model.addAttribute("userRequest", new UserRequest()); return "user/add"; } /** * 社員新規登録 * @param userRequest リクエストデータ * @param model Model * @return 社員情報一覧画面 */ @RequestMapping(value = "/user/create", method = RequestMethod.POST) public String create(@Validated @ModelAttribute UserRequest userRequest, BindingResult result, Model model) { if (result.hasErrors()) { List<String> errorList = new ArrayList<String>(); for (ObjectError error : result.getAllErrors()) { errorList.add(error.getDefaultMessage()); } model.addAttribute("validationError", errorList); return "user/add"; } // 社員情報の登録 userService.create(userRequest); return "redirect:/user/list"; } /** * 社員情報詳細画面を表示 * @param id 表示する社員番号 * @param model Model * @return 社員情報詳細画面 */ @GetMapping("/user/{id}") public String displayView(@PathVariable Long id, Model model) { User user = userService.findById(id); model.addAttribute("userRequest", user); return "user/view"; } /** * 社員編集画面を表示 * @param id 表示する社員ID * @param model Model * @return 社員編集画面 */ @GetMapping("/user/{id}/edit") public String displayEdit(@PathVariable Long id, Model model) { User user = userService.findById(id); UserUpdateRequest userUpdateRequest = new UserUpdateRequest(); userUpdateRequest.setId(user.getId()); userUpdateRequest.setName(user.getName()); userUpdateRequest.setBirthday(user.getBirthday()); userUpdateRequest.setAddress(user.getAddress()); userUpdateRequest.setPhone(user.getPhone()); userUpdateRequest.setDepartment(user.getDepartment()); model.addAttribute("userUpdateRequest", userUpdateRequest); return "user/edit"; } /** * 社員更新 * @param userRequest リクエストデータ * @param model Model * @return 社員情報詳細画面 */ @RequestMapping(value="/user/update", method=RequestMethod.POST) public String update(@Validated @ModelAttribute UserUpdateRequest userUpdateRequest, BindingResult result, Model model) { if (result.hasErrors()) { List<String> errorList = new ArrayList<String>(); for(ObjectError error : result.getAllErrors()) { errorList.add(error.getDefaultMessage()); } model.addAttribute("validationError", errorList); return "user/edit"; } // 社員情報の更新 userService.update(userUpdateRequest); return String.format("redirect:/user/%d", userUpdateRequest.getId()); } /** * 社員情報削除 * @param id 表示する社員番号 * @param model Model * @return 社員情報詳細画面 */ @GetMapping("/user/{id}/delete") public String delete(@PathVariable Long id, Model model) { // 社員情報の削除 userService.delete(id); return "redirect:/user/list"; } }
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; /** * 社員情報 Repository */ @Repository public interface UserRepository extends JpaRepository<User, Long> {}
package com.example.demo; import java.io.Serializable; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; /** * ユーザー情報 リクエストデータ */ @Data @EqualsAndHashCode(callSuper=false) public class UserRequest implements Serializable { /** * 名前 */ @NotEmpty(message = "名前を入力してください") @Size(max = 100, message = "名前は100桁以内で入力してください") private String name; /** * 生年月日 */ @Pattern(regexp = "\d{4}-\d{2}-\d{2}", message = "生年月日の形式で入力してください") private String birthday; /** * 住所 */ @NotEmpty(message = "住所を入力してください") @Size(max = 255, message = "住所は255桁以内で入力してください") private String address; /** * 電話番号 */ @Pattern(regexp = "0\d{1,4}-\d{1,4}-\d{4}", message = "電話番号の形式で入力してください") private String phone; /** * 部門 */ @NotEmpty(message = "部門を入力してください") private String department; }
package com.example.demo; import java.io.Serializable; import lombok.Data; /** * 社員情報 検索用リクエストデータ */ @Data public class UserSearchRequest implements Serializable { /** * 社員ID */ private Long id; }
package com.example.demo; import java.util.List; import javax.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** * 社員情報 Service */ @Service @Transactional(rollbackOn = Exception.class) public class UserService { /** * 社員情報 Repository */ @Autowired private UserRepository userRepository; /** * ユーザー情報 全検索 * @return 検索結果 */ public List<User> searchAll() { return userRepository.findAll(); } /** * 社員情報 新規登録 * @param user 社員情報 */ public void create(UserRequest userRequest) { userRepository.save(CreateUser(userRequest)); } /** * ユーザー情報 主キー検索 * @return 検索結果 */ public User findById(Long id) { return userRepository.findById(id).get(); } /** * 社員TBLエンティティの生成 * @param userRequest 社員情報リクエストデータ * @return 社員TBLエンティティ */ private User CreateUser(UserRequest userRequest) { User user = new User(); user.setName(userRequest.getName()); user.setBirthday(userRequest.getBirthday()); user.setAddress(userRequest.getAddress()); user.setPhone(userRequest.getPhone()); user.setDepartment(userRequest.getDepartment()); return user; } /** * 社員情報 更新 * @param user 社員情報 */ public void update(UserUpdateRequest userUpdateRequest) { User user = findById(userUpdateRequest.getId()); user.setName(userUpdateRequest.getName()); user.setBirthday(userUpdateRequest.getBirthday()); user.setAddress(userUpdateRequest.getAddress()); user.setPhone(userUpdateRequest.getPhone()); user.setDepartment(userUpdateRequest.getDepartment()); userRepository.save(user); } /** * ユーザー情報 物理削除 * @param id ユーザーID */ public void delete(Long id) { User user = findById(id); userRepository.delete(user); } }
package com.example.demo; import java.io.Serializable; import com.sun.istack.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; /** * 社員情報更新リクエストデータ * */ @Data @EqualsAndHashCode(callSuper=false) public class UserUpdateRequest extends UserRequest implements Serializable { /** * 社員ID */ @NotNull private Long id; }
### ディレクトリ ![イメージ説明](6300452c08bcf07bf399dcd4536b676d.png) ### 補足情報(FW/ツールのバージョンなど) eclipseを使用。 ※文字数が足りないため、下にHTMLとpom.xmlを記載します。

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

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

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

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

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

m.ts10806

2020/10/21 11:17

Spring,Thymeleaf をタグとして追加してください。 あと、コードが長いのであれば、現象が再現する最小構成のコードを改めて作った方が良いです。回答までつかうとキリがありませんし、それだけ自身で問題の切り分けができていないということになります。 丸投げ感が増します
guest

回答2

0

UserUpdateRequest の @NotNull にて、javax.validation.constraints.NotNullではないクラスをインポートしているためエラーが出力され、エラーページが表示されているかと。

diff

1- import com.sun.istack.NotNull; 2+ import javax.validation.constraints.NotNull;

投稿2020/10/21 13:16

A-pZ

総合スコア12011

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

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

0

※文字数が収まりきらなかったため、HTMLをここに記述

HTML

//追加 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <title>従業員新規登録</title> <link href="/css/add.css" rel="stylesheet"></link> <meta charset="utf-8" /> </head> <body> <table> <tr th:if="${validationError}" th:each="error : ${validationError}"> <td style="color:red;" th:text="${error}"></td> </tr> </table> <h1>従業員新規登録</h1> <form th:action="@{/user/create}" th:object="${userRequest}" th:method="post"> <a href="/user/list">キャンセル</a> <table> <tr> <th class="cell_title">名前</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{name}"></td> </tr> <tr> <th class="cell_title">生年月日</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{birthday}"></td> </tr> <tr> <th class="cell_title">住所</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{address}"></td> </tr> <tr> <th class="cell_title">電話番号</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{phone}"></td> </tr> <tr> <th class="cell_title">部門</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{department}"></td> </tr> </table> <div class="btn_area_center"><input type="submit" value="登録" class="btn"></div> </form> </body> </html>
!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <title>従業員情報編集</title> <link href="/css/add.css" rel="stylesheet"></link> <meta charset="utf-8" /> </head> <body> <table> <tr th:if="${validationError}" th:each="error : ${validationError}"> <td style="color:red;" th:text="${error}"></td> </tr> </table> <h1>従業員情報編集</h1> <form th:action="@{/user/update}" th:object="${userUpdateRequest}" th:method="post"> <a th:href="@{/user/{id}(id=*{id})}">キャンセル</a> <input type="hidden" th:field="*{id}" /> <table> <tr> <th class="cell_title">名前</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{name}"></td> </tr> <tr> <th class="cell_title">生年月日</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{birthday}"></td> </tr> <tr> <th class="cell_title">住所</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{address}"></td> </tr> <tr> <th class="cell_title">電話番号</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{phone}"></td> </tr> <tr> <th class="cell_title">部門</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{department}"></td> </tr> </table> <div class="btn_area_center"><input type="submit" value="保存" class="btn"></div> </form> </body> </html>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <title>従業員情報一覧</title> <link href="/css/list.css" rel="stylesheet"></link> <meta charset="utf-8" /> </head> <body> <h1>某株式会社 従業員情報一覧</h1> <div><a th:href="@{/user/add}">新規登録はこちらから</a></div> <table> <thead> <tr> <th>社員番号</th> <th>名前</th> <th>生年月日</th> <th>住所</th> <th>電話番号</th> <th>部門</th> <th> </th> </tr> </thead> <tbody> <tr th:each="user : ${userlist}" th:object="${user}"> <td class="center" th:text="*{id}"></td> <td th:text="*{name}"></td> <td class="center" th:text="*{birthday}"></td> <td th:text="*{address}"></td> <td class="center" th:text="*{phone}"></td> <td th:text="*{department}"></td> <td class="center"><a th:href="@{/user/{id}(id=*{id})}">詳細</a></td> </tr> </tbody> </table> </body> </html>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <title>社員情報詳細</title> <link href="/css/add.css" rel="stylesheet"></link> <meta charset="utf-8" /> </head> <body> <h1>社員情報詳細</h1> <table th:object="${userRequest}"> <tr> <th class="cell_title">名前</th> <th class="cell_required"></th> <td th:text="*{name}"></td> </tr> <tr> <th class="cell_title">生年月日</th> <th class="cell_required"></th> <td th:text="*{birthday}"></td> </tr> <tr> <th class="cell_title">住所</th> <th class="cell_required"></th> <td th:text="*{address}"></td> </tr> <tr> <th class="cell_title">電話番号</th> <th class="cell_required"></th> <td th:text="*{phone}"></td> </tr> <tr> <th class="cell_title">部門</th> <th class="cell_required"></th> <td th:text="*{department}"></td> </tr> </table> <div class="btn_area_center"> <a th:href="@{/user/{id}/edit(id=*{id})}">編集</a> <a th:href="@{/user/{id}/delete(id=*{id})}">削除</a> <a href="/user/list">一覧に戻る</a> </div> </body> </html>

pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>ShainList</artifactId> <version>0.0.1-SNAPSHOT</version> <name>ShainList</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.el</artifactId> <version>3.0.1-b09</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

投稿2020/10/21 11:11

NakkaFive

総合スコア2

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

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

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

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問