質問編集履歴

1

Homeコントローラー追加しました

2018/11/15 04:10

投稿

G-ym
G-ym

スコア16

test CHANGED
File without changes
test CHANGED
@@ -371,3 +371,77 @@
371
371
 
372
372
 
373
373
  ```
374
+
375
+ ```java
376
+
377
+ import java.util.List;
378
+
379
+
380
+
381
+ import org.springframework.beans.factory.annotation.Autowired;
382
+
383
+ import org.springframework.stereotype.Controller;
384
+
385
+ import org.springframework.ui.Model;
386
+
387
+ import org.springframework.web.bind.annotation.GetMapping;
388
+
389
+ import org.springframework.web.bind.annotation.PostMapping;
390
+
391
+
392
+
393
+ import com.example.demo.login.domain.model.User;
394
+
395
+ import com.example.demo.login.domain.service.UserService;
396
+
397
+
398
+
399
+ @Controller
400
+
401
+ public class HomeController {
402
+
403
+ @Autowired
404
+
405
+ UserService userService;
406
+
407
+
408
+
409
+ @GetMapping("/home")
410
+
411
+ public String getHome(Model model) {
412
+
413
+ model.addAttribute("contents","home/home :: home_contents");
414
+
415
+ return "home/homeLayout";
416
+
417
+ }
418
+
419
+ @PostMapping("/logout")
420
+
421
+ public String posthome() {
422
+
423
+ return"redirect:/login";
424
+
425
+ }
426
+
427
+
428
+
429
+ @GetMapping("/userList")
430
+
431
+ public String getUserList(Model model) {
432
+
433
+ model.addAttribute("contents","home/userList :: userList_contents");
434
+
435
+ List<User> userList = userService.selectMany();
436
+
437
+ model.addAttribute("userList",userList);
438
+
439
+ return "home/userList";
440
+
441
+ }
442
+
443
+ }
444
+
445
+
446
+
447
+ ```