質問編集履歴

5

追記

2020/10/27 08:28

投稿

mitulu
mitulu

スコア2

test CHANGED
File without changes
test CHANGED
@@ -300,7 +300,7 @@
300
300
 
301
301
 
302
302
 
303
- ### 解決方法
303
+ ### (追記) 解決方法
304
304
 
305
305
  別ファイルにクラスを用意して継承させました。
306
306
 

4

継承させて解決しました。

2020/10/27 08:28

投稿

mitulu
mitulu

スコア2

test CHANGED
File without changes
test CHANGED
@@ -295,3 +295,49 @@
295
295
  Spring Boot
296
296
 
297
297
  Gladle
298
+
299
+
300
+
301
+
302
+
303
+ ### 解決方法
304
+
305
+ 別ファイルにクラスを用意して継承させました。
306
+
307
+ AllController.java
308
+
309
+ ```
310
+
311
+ public abstract class AllController {
312
+
313
+ @ModelAttribute("toppageSearch")
314
+
315
+ ToppageSearch setupForm() {
316
+
317
+ return new ToppageSearch();
318
+
319
+ }
320
+
321
+
322
+
323
+ @ModelAttribute("categorylist")
324
+
325
+ List<Category> setuplist() {
326
+
327
+ ~~~~
328
+
329
+ return categorylist;
330
+
331
+ }
332
+
333
+ ```
334
+
335
+ 参照先のController
336
+
337
+ ```
338
+
339
+ @Controller
340
+
341
+ public class Mitulu extends AllController {
342
+
343
+ ```

3

ソース修正

2020/10/27 08:27

投稿

mitulu
mitulu

スコア2

test CHANGED
File without changes
test CHANGED
@@ -212,18 +212,12 @@
212
212
 
213
213
  @Controller
214
214
 
215
- @SessionAttributes({"toppageSearch", "loginUser"}) //追加
215
+ @SessionAttributes({"toppageSearch", "categorylist"}) //追加
216
216
 
217
217
  public class ToppageController extends AllController {
218
218
 
219
219
 
220
220
 
221
- @Autowired
222
-
223
- HttpSession session;
224
-
225
-
226
-
227
221
  @ModelAttribute("toppageSearch")
228
222
 
229
223
  ToppageSearch setupForm() {
@@ -234,21 +228,13 @@
234
228
 
235
229
 
236
230
 
237
- //追加
238
-
239
- @ModelAttribute("loginUser")
231
+ @ModelAttribute("categorylist")
240
-
232
+
241
- loginUser setupId() {
233
+ List<Category> setuplist() {
242
-
243
- if(session.getAttribute("user") != null) {
234
+
244
-
245
- loginUser loginuser = (loginUser)session.getAttribute("user");
246
-
247
- System.out.println(loginuser);
235
+ ~~~~
248
-
236
+
249
- return loginuser;
237
+ return categorylist;
250
-
251
- }
252
238
 
253
239
  }
254
240
 
@@ -270,7 +256,7 @@
270
256
 
271
257
  @Controller
272
258
 
273
- @SessionAttributes({"toppageSearch", "loginUser"}) //追加
259
+ @SessionAttributes({"toppageSearch", "categorylist"}) //追加
274
260
 
275
261
  public class AA {
276
262
 

2

ソースを修正。

2020/10/26 09:01

投稿

mitulu
mitulu

スコア2

test CHANGED
File without changes
test CHANGED
@@ -78,69 +78,7 @@
78
78
 
79
79
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
80
80
 
81
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
82
-
83
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
81
+ ~~~
84
-
85
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
86
-
87
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
88
-
89
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
90
-
91
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
92
-
93
- at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
94
-
95
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
96
-
97
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
98
-
99
- at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
100
-
101
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
102
-
103
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
104
-
105
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
106
-
107
- at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
108
-
109
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
110
-
111
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
112
-
113
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
114
-
115
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
116
-
117
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
118
-
119
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
120
-
121
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
122
-
123
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
124
-
125
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
126
-
127
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
128
-
129
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
130
-
131
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
132
-
133
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
134
-
135
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
136
-
137
- at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
138
-
139
- at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
140
-
141
- at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
142
-
143
- at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589)
144
82
 
145
83
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
146
84
 
@@ -268,23 +206,25 @@
268
206
 
269
207
  ```
270
208
 
271
-
272
-
273
- Controller
209
+ 参照元のController
274
-
275
-
276
210
 
277
211
  ```
278
212
 
279
213
  @Controller
280
214
 
215
+ @SessionAttributes({"toppageSearch", "loginUser"}) //追加
216
+
281
217
  public class ToppageController extends AllController {
282
218
 
283
219
 
284
220
 
285
-
221
+ @Autowired
222
+
286
-
223
+ HttpSession session;
224
+
225
+
226
+
287
- @ModelAttribute
227
+ @ModelAttribute("toppageSearch")
288
228
 
289
229
  ToppageSearch setupForm() {
290
230
 
@@ -294,6 +234,28 @@
294
234
 
295
235
 
296
236
 
237
+ //追加
238
+
239
+ @ModelAttribute("loginUser")
240
+
241
+ loginUser setupId() {
242
+
243
+ if(session.getAttribute("user") != null) {
244
+
245
+ loginUser loginuser = (loginUser)session.getAttribute("user");
246
+
247
+ System.out.println(loginuser);
248
+
249
+ return loginuser;
250
+
251
+ }
252
+
253
+ }
254
+
255
+
256
+
257
+
258
+
297
259
  @RequestMapping(value = "/Toppage", method = RequestMethod.GET)
298
260
 
299
261
  public String displayTop(Model model) {
@@ -302,6 +264,38 @@
302
264
 
303
265
  ```
304
266
 
267
+ 参照先のController
268
+
269
+ ```
270
+
271
+ @Controller
272
+
273
+ @SessionAttributes({"toppageSearch", "loginUser"}) //追加
274
+
275
+ public class AA {
276
+
277
+
278
+
279
+ @RequestMapping("/mitulu")
280
+
281
+ public String mitulu() {
282
+
283
+ return "mitulu";
284
+
285
+ }
286
+
287
+
288
+
289
+ }
290
+
291
+ ...
292
+
293
+ ```
294
+
295
+
296
+
297
+
298
+
305
299
  (/Toppageでは動作します。)
306
300
 
307
301
 

1

ファイル名 訂正

2020/10/26 08:58

投稿

mitulu
mitulu

スコア2

test CHANGED
File without changes
test CHANGED
@@ -248,7 +248,7 @@
248
248
 
249
249
  ```
250
250
 
251
- header.html
251
+ Toppage.html
252
252
 
253
253
  ```
254
254