質問編集履歴
3
judgeController.javaの相対パスを訂正しました。また、エラーメッセージが変わったのでそちらも更新しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Spring Bootを使って、入力フォーム(info-form.html)で車の速度を受け取り、その速度によって出力結果が変わる出力フォーム(judge.html)を作成したいです。
|
2
|
-
しかし、入力を受け取ってから実際の出力ページに移動すると
|
2
|
+
しかし、入力を受け取ってから実際の出力ページに移動すると500とエラーが発生しました。
|
3
3
|
|
4
4
|
|
5
5
|
|
@@ -12,9 +12,11 @@
|
|
12
12
|
Whitelabel Error Page
|
13
13
|
This application has no explicit mapping for /error, so you are seeing this as a fallback.
|
14
14
|
|
15
|
-
|
15
|
+
Thu Jan 26 23:20:56 JST 2023
|
16
|
-
There was an unexpected error (type=
|
16
|
+
There was an unexpected error (type=Internal Server Error, status=500).
|
17
|
+
Unresolved compilation problem: The method setSpeed(int) in the type Car is not applicable for the arguments (String)
|
17
|
-
|
18
|
+
java.lang.Error: Unresolved compilation problem:
|
19
|
+
The method setSpeed(int) in the type Car is not applicable for the arguments (String)
|
18
20
|
|
19
21
|
|
20
22
|
### 該当のソースコード
|
@@ -81,7 +83,7 @@
|
|
81
83
|
return "info-form";
|
82
84
|
}
|
83
85
|
|
84
|
-
@RequestMapping("
|
86
|
+
@RequestMapping("/receive-info")
|
85
87
|
public String inputSpeed(String speed,Model model) {
|
86
88
|
Car car = new Car();
|
87
89
|
|
2
エラーメッセージの追加と補足情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,6 +10,11 @@
|
|
10
10
|
|
11
11
|
### 発生している問題・エラーメッセージ
|
12
12
|
Whitelabel Error Page
|
13
|
+
This application has no explicit mapping for /error, so you are seeing this as a fallback.
|
14
|
+
|
15
|
+
Wed Jan 25 23:14:59 JST 2023
|
16
|
+
There was an unexpected error (type=Not Found, status=404).
|
17
|
+
No message available
|
13
18
|
|
14
19
|
|
15
20
|
### 該当のソースコード
|
@@ -155,5 +160,6 @@
|
|
155
160
|
|
156
161
|
|
157
162
|
### 補足情報(FW/ツールのバージョンなど)
|
158
|
-
Springのバージョンは
|
163
|
+
Springのバージョンは3.0
|
164
|
+
javaのバージョンは17です。
|
159
165
|
|
1
ソースコードの記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,15 +13,143 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
### 該当のソースコード
|
16
|
+
```html
|
17
|
+
~info-form.html~
|
18
|
+
<!DOCTYPE html>
|
16
|
-
|
19
|
+
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
|
20
|
+
|
21
|
+
<head>
|
22
|
+
<meta charset="utf-8">
|
23
|
+
<title> Insert title here </title>
|
24
|
+
</head>
|
25
|
+
|
26
|
+
<body>
|
27
|
+
速度を入力してください<br>
|
17
|
-
|
28
|
+
<form action="if-unless.html" th:action="@{/receive/receive-info}" method="post">
|
18
|
-
|
29
|
+
<input type="text" name="speed"><br>
|
19
|
-
|
30
|
+
<button>送信</button>
|
31
|
+
<form />
|
32
|
+
</body>
|
33
|
+
|
34
|
+
</html>
|
35
|
+
|
36
|
+
|
37
|
+
~judge .html~
|
38
|
+
<!DOCTYPE html>
|
20
|
-
|
39
|
+
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
|
40
|
+
|
41
|
+
<head>
|
42
|
+
<meta charset="utf-8">
|
43
|
+
<title> Insert title here </title>
|
44
|
+
</head>
|
45
|
+
|
46
|
+
<body>
|
47
|
+
<span th:if="${car.speed <= 60}" th:text="法定速度です">dummy</span>
|
48
|
+
|
49
|
+
<span th:unless="${car.speed <= 60}" th;text="スピード違反です">dummy</span>
|
50
|
+
|
51
|
+
</html>
|
52
|
+
```
|
53
|
+
```java
|
54
|
+
~JudgeController.java~
|
55
|
+
package com.example.controller;
|
56
|
+
|
57
|
+
import org.springframework.stereotype.Controller;
|
58
|
+
import org.springframework.ui.Model;
|
59
|
+
import org.springframework.web.bind.annotation.ModelAttribute;
|
60
|
+
import org.springframework.web.bind.annotation.RequestMapping;
|
61
|
+
|
62
|
+
import com.example.Form.ReceiveForm;
|
63
|
+
import com.example.domain.Car;
|
64
|
+
|
65
|
+
@Controller
|
66
|
+
@RequestMapping("/receive")
|
67
|
+
public class JudgeController {
|
68
|
+
|
69
|
+
@ModelAttribute
|
70
|
+
public ReceiveForm setUpForm() {
|
71
|
+
return new ReceiveForm();
|
72
|
+
}
|
73
|
+
|
74
|
+
@RequestMapping("")
|
75
|
+
public String index() {
|
76
|
+
return "info-form";
|
77
|
+
}
|
78
|
+
|
79
|
+
@RequestMapping("receive/receive-info")
|
80
|
+
public String inputSpeed(String speed,Model model) {
|
81
|
+
Car car = new Car();
|
82
|
+
|
83
|
+
int speed = 0;
|
84
|
+
|
85
|
+
model.addAttribute("speed",speed);
|
86
|
+
|
87
|
+
car.setSpeed(speed);
|
88
|
+
|
89
|
+
return "judge";
|
90
|
+
}
|
91
|
+
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
~ReceiveForm.java~
|
97
|
+
package com.example.Form;
|
98
|
+
|
99
|
+
public class ReceiveForm {
|
100
|
+
private String name;
|
101
|
+
private String speed;
|
102
|
+
|
103
|
+
public String getName() {
|
104
|
+
return name;
|
105
|
+
}
|
106
|
+
public void setName(String name) {
|
107
|
+
this.name = name;
|
108
|
+
}
|
109
|
+
public String getSpeed() {
|
110
|
+
return speed;
|
111
|
+
}
|
112
|
+
public void setSpeed(String speed) {
|
113
|
+
this.speed = speed;
|
114
|
+
}
|
115
|
+
|
116
|
+
@Override
|
117
|
+
public String toString() {
|
118
|
+
return "ReceiveForm [name=" + name + ", speed=" + speed + "]";
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
~Car.java~
|
125
|
+
package com.example.domain;
|
126
|
+
|
127
|
+
public class Car {
|
128
|
+
private String name;
|
129
|
+
private int speed;
|
130
|
+
|
131
|
+
public String getName() {
|
132
|
+
return name;
|
133
|
+
}
|
134
|
+
|
135
|
+
public void setName(String name) {
|
136
|
+
this.name = name;
|
137
|
+
}
|
138
|
+
|
139
|
+
public int getSpeed() {
|
140
|
+
return speed;
|
141
|
+
}
|
142
|
+
|
143
|
+
public void setSpeed(int speed) {
|
144
|
+
this.speed = speed;
|
145
|
+
}
|
146
|
+
|
147
|
+
}
|
148
|
+
```
|
21
149
|
|
22
150
|
### 試したこと
|
23
151
|
|
24
|
-
・各ファイルの格納場所は問題ないと考えております。
|
152
|
+
・各ファイルの格納場所は問題ないと考えております。
|
25
153
|
・恐らく、JudgeControllerのコード(inputSpeedメソッド)が違うと思うのですが、
|
26
154
|
考えても分からないため、何卒ご教示願います。
|
27
155
|
|