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

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

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

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

Q&A

1回答

353閲覧

springtoolsuite4で ログイン画面を作成しています.

hhhkkk

総合スコア0

Spring Boot

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

0グッド

0クリップ

投稿2023/03/16 15:35

springtoolsuite4で ログイン画面を作成しています.

Whitelabel

1This application has no explicit mapping for /error, so you are seeing this as a fallback. 2 3Fri Mar 17 00:28:32 JST 2023 4There was an unexpected error (type=Not Found, status=404). 5No message available``` 6 7ブラウザからlocalhost:8080/loginと接続をしたところ 8このようなエラーが表示されました. 9 10![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-03-17/a391324e-c4e7-4799-8af4-af4076036b71.png) 11 12このような構成となっており, 13```package com.example.application.service; 14 15import java.util.LinkedHashMap; 16import java.util.Map; 17 18import org.springframework.stereotype.Service; 19 20@Service 21public class UserApplicationService { 22 /**性別のMapを作成する*/ 23 public Map<String,Integer> getGenderMap(){ 24 Map<String,Integer> genderMap=new LinkedHashMap<>(); 25 genderMap.put("男性", 1); 26 genderMap.put("女性", 2); 27 return genderMap; 28 } 29}

package

1 2import org.springframework.stereotype.Controller; 3import org.springframework.web.bind.annotation.GetMapping; 4 5@Controller 6public class LoginController { 7 /**ログイン画面を表示*/ 8 @GetMapping("/loing") 9 public String getLogin() { 10 return "login/login"; 11 } 12}

package

1 2import java.util.Map; 3 4import org.springframework.beans.factory.annotation.Autowired; 5import org.springframework.stereotype.Controller; 6import org.springframework.ui.Model; 7import org.springframework.web.bind.annotation.GetMapping; 8import org.springframework.web.bind.annotation.PostMapping; 9import org.springframework.web.bind.annotation.RequestMapping; 10 11import com.example.application.service.UserApplicationService; 12 13@Controller 14@RequestMapping("/user") 15public class SignupController { 16 17 @Autowired 18 private UserApplicationService userApplicationService; 19 20 /**ユーザー登録画面を表示*/ 21 @GetMapping("/signup") 22 public String getSignup(Model model) { 23 //性別を取得 24 Map<String,Integer> genderMap=userApplicationService.getGenderMap(); 25 model.addAttribute("genderMap",genderMap); 26 27 //ユーザー登録画面に遷移 28 return "user/signup"; 29 } 30 31 /**ユーザー登録処理*/ 32 @PostMapping("/signup") 33 public String postSignup() { 34 //ログイン画面にリダイレクト 35 return "redirect:/login"; 36 } 37 38}
<html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"> <!--CSS読込--> <link rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"> <link rel="stylesheet" th:href="@{/css/user/signup.css}"> <!--JS読込--> <script th:src="@{webjars/jquery/jquery.min.js}" defer></script> <script th:src="@{webjars/bootstrap/js/bootstrap.min.js}" defer></script> <title>ユーザー登録</title> </head> <body class="bg-light"> <form id="signup-form" method="post" action="/user/signup" class="form-signup"> <h1 class="text-center">ユーザー登録</h1> <!--ユーザーID--> <div class="form-group"> <label for="userId">ユーザーID</label> <input type="text" class="form-control"/> </div> <!--パスワード--> <div class="form-group"> <label for="password">パスワード</label> <input type="text" class="form-control"/> </div> <!--誕生日--> <div class="form-group"> <label for="birthday">誕生日</label> <input type="text" class="form-control"/> </div> <!--年齢--> <div class="form-group"> <label for="age">年齢</label> <input type="text" class="form-control"/> </div> <!--性別--> <div class="form-group"> <div th:each="item:${genderMap}" class="form-check-inline"> <input type="radio" class="form-check-input" th:value="${item.value}"/> <label class="form-check-label" th:text="${item.key}"></label> </div> </div> <!--登録ボタン--> <input type="submit" value="ユーザー登録" class="btn btn-primary w-100 mt-3"/> </form> </body> </html>``` エラーの原因はどこにあります.ご教授お願いします.

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

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

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

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

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

m.ts10806

2023/03/16 20:47

本文全てがマークダウンのcodeとなってしまっているので調整してください。 ``` で囲われているとそうなります。 投稿前にプレビューを確認してください。(PCなら画面右側がプレビューです)
guest

回答1

0

ブラウザからlocalhost:8080/loginと接続をしたところ

マッピングが@GetMapping("/loing")となっていますので現状の実装だと/loginは存在しません。


本件とは無関係ですが、アプリケーション内で扱うURLは全て@{hoge}の形式を利用しましょう。
cssやjsはその形式が採用されていますが、formのaction属性などなっていません。

投稿2023/03/16 20:50

m.ts10806

総合スコア80850

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問