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

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

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

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

Spring Boot

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

Q&A

解決済

1回答

437閲覧

SpringBootで初期画面が出ない

onoko

総合スコア40

Java

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

Spring Boot

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

0グッド

0クリップ

投稿2022/09/05 07:07

前提

SpringBoot 初心者です。
消費税計算のプログラムを作っています。事業区分ごとの税込売上高を入力し、「計算」のボタンをクリックすると、税額算出画面に計算式と納付税額が表示される仕組みです。
ところが、Thymeleafを使ったhtmlのトップ画面を出そうとしているのですけれど、これが出ません。
次のようなエラーメッセージが出るのですが、その指摘する箇所を検討してみても正しいように見えて原因が分かりません。
どこに根本的な誤りがあるのかをできましたらご教授願いたいのですが。

実現したいこと

トップ画面を表示する機能を動作するようにする。

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

トップ画面が出ない。

Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "taxCalc/top" - line 25, col 59)

該当のソースコード

java

1package com.example.demo.web; 2 3import org.springframework.stereotype.Controller; 4import org.springframework.web.bind.annotation.GetMapping; 5import org.springframework.web.bind.annotation.ModelAttribute; 6import org.springframework.web.bind.annotation.PostMapping; 7import org.springframework.web.bind.annotation.RequestMapping; 8 9@Controller 10@RequestMapping("taxCalc") 11public class taxCalcController { 12 13@ModelAttribute 14SalesForm setupForm() { 15 return new SalesForm(); 16} 17 18@GetMapping 19String top() { 20 return "taxCalc/top"; 21} 22 23@PostMapping(params="taxCalc") 24String result() { 25 return "taxCalc/result"; 26} 27 28@GetMapping(params="goToTop") 29String goToTop() { 30 return "taxCalc/top"; 31} 32} 33

java

1package com.example.demo.web; 2 3import javax.validation.constraints.PositiveOrZero; 4 5public class SalesForm { 6 @PositiveOrZero 7 private Integer sales1_8; 8 @PositiveOrZero 9 private Integer salesRET1_8; 10 @PositiveOrZero 11 private Integer sales1_10; 12 @PositiveOrZero 13 private Integer salesRET1_10; 14 @PositiveOrZero 15 private Integer sales2_8; 16 @PositiveOrZero 17 private Integer salesRET2_8; 18 @PositiveOrZero 19 private Integer sales2_10; 20 @PositiveOrZero 21 private Integer salesRET2_10; 22 @PositiveOrZero 23 private Integer sales3_8; 24 @PositiveOrZero 25 private Integer salesRET3_8; 26 @PositiveOrZero 27 private Integer sales3_10; 28 @PositiveOrZero 29 private Integer salesRET3_10; 30 @PositiveOrZero 31 private Integer sales4_8; 32 @PositiveOrZero 33 private Integer salesRET4_8; 34 @PositiveOrZero 35 private Integer sales4_10; 36 @PositiveOrZero 37 private Integer salesRET4_10; 38 @PositiveOrZero 39 private Integer sales5_10; 40 @PositiveOrZero 41 private Integer salesRET5_10; 42 @PositiveOrZero 43 private Integer sales6_10; 44 @PositiveOrZero 45 private Integer salesRET6_10; 46} 47

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:action="@{/taxCalc/result}" th:object="${salesForm}" method="post"> 10<div id="userForm-errors" th:errors="*{*}" class="error-message-list"></div> 11<table border="1"> 12 <tr> 13 <th>事業区分</th> 14 <th>業種</th> 15 <th>みなし仕入率</th> 16 <th>8%売上(税込)</th> 17 <th>8%売上返還(税込)</th> 18 <th>10%売上(税込)</th> 19 <th>10%売上返還(税込)</th> 20 </tr> 21 <tr> 22 <th>第一種事業</th> 23 <th>卸売業</th> 24 <th>90%</th> 25 <td><input type="text" id="sales1_8" name="sales1_8" th:field="*{sales1_8}" value=0 th:errorclass="error-input"/></td> 26 <td><input type="text" id="salesRET1_8" name="salesRET1_8" th:field="*{salesRET1_8}" value=0 th:errorclass="error-input"/></td> 27 <td><input type="text" id="sales1_10" name="sales1_10" th:field="*{sales1_10}" value=0 th:errorclass="error-input"/></td> 28 <td><input type="text" id="salesRET1_10" name="salesRET1_10" th:field="*{salesRET1_10}" value=0 th:errorclass="error-input"/></td> 29 </tr> 30 <tr> 31 <th>第二種事業</th> 32 <th></th> 33 <th>80%</th> 34 <td><input type="text" id="sales2_8" name="sales2_8" th:field="*{sales2_8}" value=0 th:errorclass="error-input"/></td> 35 <td><input type="text" id="salesRET2_8" name="salesRET2_8" th:field="*{salesRET2_8}" value=0 th:errorclass="error-input"/></td> 36 <td><input type="text" id="sales2_10" name="sales2_10" th:field="*{sales2_10}" value=0 th:errorclass="error-input"/></td> 37 <td><input type="text" id="salesRET2_10" name="salesRET2_10" th:field="*{salesRET2_10}" value=0 th:errorclass="error-input"/></td> 38 </tr> 39 <tr> 40 <th>第三種事業</th> 41 <th></th> 42 <th>70%</th> 43 <td><input type="text" id="sales3_8" name="sales3_8" th:field="*{sales3_8}" value=0 th:errorclass="error-input"/></td> 44 <td><input type="text" id="salesRET3_8" name="salesRET3_8" th:field="*{salesRET3_8}" value=0 th:errorclass="error-input"/></td> 45 <td><input type="text" id="sales3_10" name="sales3_10" th:field="*{sales3_10}" value=0 th:errorclass="error-input"/></td> 46 <td><input type="text" id="salesRET3_10" name="salesRET3_10" th:field="*{salesRET3_10}" value=0 th:errorclass="error-input"/></td> 47 </tr> 48 <tr> 49 <th>第四種事業</th> 50 <th></th> 51 <th>60%</th> 52 <td><input type="text" id="sales4_8" name="sales4_8" th:field="*{sales4_8}" value=0 th:errorclass="error-input"/></td> 53 <td><input type="text" id="salesRET4_8" name="salesRET4_8" th:field="*{salesRET4_8}" value=0 th:errorclass="error-input"/></td> 54 <td><input type="text" id="sales4_10" name="sales4_10" th:field="*{sales4_10}" value=0 th:errorclass="error-input"/></td> 55 <td><input type="text" id="salesRET4_10" name="salesRET4_10" th:field="*{salesRET4_10}" value=0 th:errorclass="error-input"/></td> 56 </tr> 57 <tr> 58 <th>第五種事業</th> 59 <th></th> 60 <th>50%</th> 61 <td></td> 62 <td></td> 63 <td><input type="text" id="sales5_10" name="sales5_10" th:field="*{sales5_10}" value=0 th:errorclass="error-input"/></td> 64 <td><input type="text" id="salesRET5_10" name="salesRET5_10" th:field="*{salesRET5_10}" value=0 th:errorclass="error-input"/></td> 65 </tr> 66 <tr> 67 <th>第六種事業</th> 68 <th>不動産業</th> 69 <th>40%</th> 70 <td></td> 71 <td></td> 72 <td><input type="text" id="sales6_10" name="sales6_10" th:field="*{sales6_10}" value=0 th:errorclass="error-input"/></td> 73 <td><input type="text" id="salesRET6_10" name="salesRET6_10" th:field="*{salesRET6_10}" value=0 th:errorclass="error-input"/></td> 74 </tr> 75</table> 76<input type="submit"name="taxCalc" value="計算"/> 77</form> 78</body> 79</html>

試したこと

エラーの起きている箇所をコメントアウトしたのちただの<td></td>に置き換えて再実行しても、次の行にエラーが移るだけ。

エラーを指摘された箇所(nameの名前”sales1_8"のs)を含め名前に使用する文字に不適当はない。

補足情報(FW/ツールのバージョンなど)

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

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

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

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

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

m.ts10806

2022/09/05 07:26

value=0 上記のように属性値がクォーテーションで閉じられていないところを閉じた場合はどうなりますか?
onoko

2022/09/05 08:08

実行してみたところエラーで、同じエラーメッセージがでました。
m.ts10806

2022/09/05 08:12

なるほど。あくまでテンプレートの文法上のエラーなのは間違いないので、 taxCalc/top" (提示されたhtmlでしょうか?)の 25行目, 59列目付近で気になるところを出してみました。
onoko

2022/09/05 08:22 編集

仔細にいたるご指摘ありがとうございます。また私が提示したhtmlの名前は top.html で、注釈不足でした。
m.ts10806

2022/09/05 08:32

あまり関係なさそうですが、小さい可能性でも潰したいので以下も確認してみてください。 inputタグってそもそも閉じタグがないので / って後ろに書く必要がないです。 HTML的に問題はないですが、精密チェックだと警告くらいは出るかもしれません。
onoko

2022/09/05 08:46

SpringBootの教本のサンプルの<input>が、/>で閉じてあったため写しました。その前はお勧め通りの、>で閉じていたのですが、その際にも同一のエラーが出ていました。なにはともあれ、/を取ってみます。
m.ts10806

2022/09/05 08:48

いえ、おそらく関係ないと思いつつ、どこかで引っ掛かってる可能性を模索してる感じです。 ※手元で環境が組めてないのでそこは申し訳ない
m.ts10806

2022/09/05 08:50

そういえば、そもそも salesForm というオブジェクトがVIEWに渡るように書けていないように思うのですが、如何でしょうか。
onoko

2022/09/05 08:54

/をとってやってみました。同じエラーが出ました。
onoko

2022/09/05 10:14

画面の第一番目の項目からエラーが出るということは、そもそも画面にオブジェクトが渡っていないことを意味していて、おっしゃる通りだからだと存じます。そこで使い慣れない@ModelAttributeをやめて、1メソッドずつ、model.addAttribute("salesForm",salesForm)を、またGetMappingtとPostMappingの修飾するメソッドの引数に(@Validated SalesForm salesForm,Model model)をコードして、画面にデータを移転しようと実行しましたが、表示されず、同じエラーメッセージがまた出ました。思うにSalesFormをnewするタイミングが不明なためもあるかと存じます。どうかこの状態を解消するためのご指導をよろしくお願いいたします。
m.ts10806

2022/09/05 10:42

念のため書き直したコードを提示してもらっても良いですか? 現状だとどのパターンでもSalesFormは渡っても各項目は全部nullになってる気がするので。
onoko

2022/09/05 11:08

画面出ました。原因は、SalesFormクラスに、getterとsetterの機能を自明のものとする、SpringBootの機能の処理上必要とされるらしい、lombok をimpotしていなかったからで、ログの末尾あたりにそういうことが出ているのに気が付いて、解明につながったのでした。問題は解決しました。丁寧でご親切なお付き合い誠にありがとうございました。
m.ts10806

2022/09/05 11:11

あぁなるほど。 ひとまず顛末を自身で回答として記載して自己解決としてください。 その出てたログの部分を回答に貼っておくと後から見る人にも参考になると思いますので。
guest

回答1

0

自己解決

オブジェクトのクラスに、SpringBootの機能上必用とされるらしい、オブジェクトの項目のgetterとsetterを自動で用意する lombok.Data をimportしたうえで、@DataアノテーションをSalesFormクラスに付加して実行したら、画面が表示された。

投稿2022/09/05 11:19

onoko

総合スコア40

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問