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

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

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

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

Q&A

0回答

5231閲覧

正常な画面遷移が行いたい

python567

総合スコア12

Spring

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

0グッド

0クリップ

投稿2019/06/25 07:15

編集2019/06/25 10:09

前提・実現したいこと

プログラミング初学者です。
springを使用して、交通費精算表を作成しています。
ログイン画面から精算表に遷移は出来るのですが、精算表か精算表確認画面に遷移しようとした際にパラメーター要求を満たしていませんというエラーが出てきます。
正常に画面遷移を行いたいのですが、どのようにすればよろしいでしょうか。

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

WARN 11756 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "assign" OR "settlement" not met for actual request parameters: conf={確認}]

該当のソースコード

Javapackage

1 2import java.text.SimpleDateFormat; 3import java.util.Date; 4import java.util.List; 5 6import org.springframework.beans.BeanUtils; 7import org.springframework.beans.factory.annotation.Autowired; 8import org.springframework.stereotype.Controller; 9import org.springframework.ui.Model; 10import org.springframework.validation.BindingResult; 11import org.springframework.validation.annotation.Validated; 12import org.springframework.web.bind.annotation.ModelAttribute; 13import org.springframework.web.bind.annotation.PostMapping; 14import org.springframework.web.bind.annotation.RequestMapping; 15import org.springframework.web.bind.annotation.SessionAttributes; 16 17import com.example.domain.AssignMST; 18import com.example.domain.Day; 19import com.example.domain.EmployeeMST; 20import com.example.service.DBService; 21 22@Controller 23@SessionAttributes("assign") 24public class Settlement { 25 @Autowired 26 private DBService service; 27 28 @ModelAttribute("assign") 29 public NewassignForm newassignform() { 30 return new NewassignForm(); 31 } 32 33 @ModelAttribute("login") 34 public LoginForm loginform() { 35 return new LoginForm(); 36 } 37 38 @ModelAttribute("day") 39 public DayForm dayform() { 40 return new DayForm(); 41 } 42 43 // ログイン画面 44 @RequestMapping(value = "/") 45 public String login() { 46 return "demo/login"; 47 } 48 49 // ログイン→清算書 50 @RequestMapping(value = "/jaxs", params = "settlement") 51 public String settlement(@Validated @ModelAttribute("login") LoginForm login, BindingResult result, 52 @ModelAttribute("assign") NewassignForm assign,Model model) { 53 if (login.getUserId() == null || login.getUserId().length() == 0) { 54 result.reject("errors.login"); 55 } else { 56 AssignMST assignMST = new AssignMST(); 57 BeanUtils.copyProperties(login, assignMST); 58 service.loginck(assignMST.getUserId()); 59// BeanUtils.copyProperties(assignMST, login); 60 model.addAttribute(assignMST); 61 if (login == null) { 62 result.reject("errors.account"); 63 } 64 } // ←までエラーチェック 65 if (result.hasErrors()) { 66 return "demo/login"; // エラーがあった場合ログイン画面に再遷移 67 } else { // ←ここから清算書ビューに遷移 68 Date nowDate = new Date(); 69 SimpleDateFormat formatA = new SimpleDateFormat("yyyy/MM/dd"); 70 String today = formatA.format(nowDate); 71 assign.setToday(today); 72 AssignMST assignMST = service.userInfo(login.getUserId()); 73 BeanUtils.copyProperties(assignMST, assign); 74 75 return "demo/Settlement"; 76 } 77 } 78 //清算書→ログアウト 79 @RequestMapping(value="/java", params= "logout") 80 public String logout() { 81 return "demo/login"; 82 } 83 84 // 清算書→清算書確認 85 @RequestMapping(value = "/java", params= "conf") 86 public String gonext(@ModelAttribute("assign") NewassignForm assign, @ModelAttribute("day") DayForm day) { 87 88 89 Date nowDate = new Date(); SimpleDateFormat formatA = new 90 SimpleDateFormat("yyyy/MM/dd"); String today = formatA.format(nowDate); 91 assign.setToday(today); List<Day> todaycal = 92 service.todaycal(assign.getSelectYear(), assign.getSelectMonth()); 93 BeanUtils.copyProperties(todaycal, day); AssignMST assignMST 94 =service.userInfo(assign.getUserId()); BeanUtils.copyProperties(assignMST, 95 assign); 96 97 return "demo/gonext"; 98 99 } 100 101 // ログイン→新規登録 102 @RequestMapping(value = "/jaxs", params = "assign") 103 public String assign(@ModelAttribute("assign") NewassignForm assign) { 104 return "demo/assignaccount"; 105 } 106 107 // ログイン(戻る) 108 @RequestMapping(value = { "/assign", "/assignend" }, params = "login") 109 public String back() { 110 return "demo/login"; 111 } 112 113 // l新規登録→登録確認 114 @RequestMapping(value = "/assign", params = "assignconf") 115 public String assignconf(@ModelAttribute("assign") NewassignForm assign) { 116 return "demo/assignconf"; 117 } 118 119 // 登録確認→新規登録(戻る) 120 @RequestMapping(value = "/assignconf", params = "back") 121 public String confback() { 122 return "demo/assignaccount"; 123 } 124 125 // 登録確認→登録完了 126 @RequestMapping(value = "/assignconf", params = "next") 127 public String assignend(@ModelAttribute("assign") NewassignForm assign) { 128 AssignMST assignMST = new AssignMST(); 129 EmployeeMST employeeMST = new EmployeeMST(); 130 BeanUtils.copyProperties(assign, assignMST); 131 BeanUtils.copyProperties(assign, employeeMST); 132 service.assignAccount(assignMST); 133 service.assignStation(employeeMST); 134 135 return "demo/assignend"; 136 } 137 138} 139

html

1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4<meta charset="UTF-8" /> 5<title>ログイン</title> 6</head> 7<body> 8 <form th:action="@{/jaxs}" th:object="${login}" method="post"> 9 <p th:if="${#fields.hasErrors('all')}" class="red">エラーが発生しました!</p> 10 <p th:errors="*{all}" >error!</p> 11 <br /> 12 <table width="50%" height="200" style="font-size: 24pt"> 13 <tr> 14 <td>ユーザID</td> 15 <td><input type="text" th:field="*{userId}" /></td> 16 </tr> 17 </table> 18 <br /><input type="submit" name="settlement" value="ログイン" /> 19 <br /><input type="submit" name="assign" value="新規登録" /> 20 </form> 21</body> 22</html>

html

1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4<meta charset="UTF-8" /> 5<title>交通費精算</title> 6</head> 7<body> 8<h1>交通費精算書</h1> 9<form th:ation="@{/java}" th:object="${assign}" method="post"> 10<p> 11 <input type="text" th:filed="*{selectYear}" />12 <input type="text" th:filed="*{selectMonth}" />月分の清算書作成 13</p> 14<table> 15 <tr> 16 <th>名前</th> 17 <th>作成日</th> 18 <th>最寄り駅</th> 19 </tr> 20 <tr> 21 <td><span th:text="*{userName}"></span></td> 22 <td><span th:text="*{today}"></span></td> 23 <td><span th:text="*{nearestStation}"></span></td> 24 </tr> 25</table> 26<table> 27 <tr> 28 <th>日付</th> 29 <th>訪問先</th> 30 <th>乗車駅</th> 31 <th></th> 32 <th>降車駅</th> 33 <th>電車</th> 34 <th>バス</th> 35 <th>タクシー</th> 36 <th>備考</th> 37 <th></th> 38 </tr> 39 <tr> 40 <td>2019/6/24</td> 41 <td></td> 42 <td></td> 43 <td></td> 44 <td></td> 45 <td></td> 46 <td></td> 47 <td></td> 48 <td></td> 49 <td></td> 50 </tr> 51</table> 52<input type="submit" name="conf" value="確認" /> 53<input type="submit" name="logout" value="ログアウト" /> 54</form> 55</body> 56</html>
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8" /> <title>交通費精算確認</title> </head> <body> <h1>交通費精算書確認</h1> <form th:ation="@{/gonext}" th:object="${assign}" method="post"> <p> <span th:text="*{selectYear}"></span>年 <span th:text="*{selectMonth}"></span>月分の清算書作成 </p> <table> <tr> <th>名前</th> <th>作成日</th> <th>最寄り駅</th> </tr> <tr> <td><span th:text="*{userName}"></span></td> <td><span th:text="*{today}"></span></td> <td><span th:text="*{nearestStation}"></span></td> </tr> </table> <table> <tr> <th>日付</th> <th>訪問先</th> <th>乗車駅</th> <th></th> <th>降車駅</th> <th>電車</th> <th>バス</th> <th>タクシー</th> <th>備考</th> <th>計</th> </tr> <tr th:each="day : ${day}"> <td th:text="${day.day}"></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> <input type="submit" value="確認" /> </form> </body> </html>

試したこと

DefaultHandlerExceptionResolverやUnsatisfiedServletRequestParameterExceptionについてかなり調べましたが、英語のサイトが多くかつどこが間違っているのかわからない状態が2日程続きましたのでご質問させていただきます。

バージョン

Spring:2.1.6.RELEASE
IDE:sts-4.2.2.RELEASE

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

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

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

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

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

m.ts10806

2019/06/25 07:44

念のため利用しているSpringのバージョンとIDEのバージョンをご提示ください。
m.ts10806

2019/06/25 07:50

あと気になるのは送信用のsubmitボタンの横にログアウトボタンが並んでたり、画面遷移とログアウト処理のマップURLが同じというところは気になりますが・・・ 例えば params= {"conf"} → params= "conf" とした場合はどうですか?
python567

2019/06/25 08:09

早速のご回答ありがとうございます。 pom.xmlで確認したところ 2.1.6.RELEASE でした。 Cドライブにはsts-4.2.2.RELEASEと表記されていてどちらが正しいのかわかりません。 IDEであっているのかわかりませんが、EclipseのバージョンはPhoton Release (4.8.0)です。 ほんとに無知で申し訳ありません。
python567

2019/06/25 08:10

params= {"conf"} → params= "conf" とした場合でも何も変化はありませんでした。
m.ts10806

2019/06/25 08:13

こちらは回答ではなく質問本文への追記修正依頼のコメント欄です。 基本的には質問を編集してお返しください。 >pom.xmlで確認したところ 2.1.6.RELEASE でした。 おそらくSpring Bootのバージョンと思います。 groupIdに”org.springframework.boot”とあったのでは? >Cドライブにはsts-4.2.2.RELEASEと表記 こちらはSTSといてEclipseのSpring用プラグインまたはIDE(STS)本体のバージョンと思います。
m.ts10806

2019/06/25 08:14 編集

>ほんとに無知で申し訳ありません。 いえいえ、謝る必要は全くありません。最初は誰もが何も知らないわけですから。 これから着実におさえて血肉にしていけば良い話です。
python567

2019/06/25 08:44

>いえいえ、謝る必要は全くありません。最初は誰もが何も知らないわけですから。 そう言って頂けると非常に励みになります。ありがとうございます。
退会済みユーザー

退会済みユーザー

2019/06/25 09:51

ポストデータでマッピング分岐ができなかったような…
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問