質問編集履歴

1

コントローラーの追加

2023/07/03 10:17

投稿

Atsugi
Atsugi

スコア4

test CHANGED
File without changes
test CHANGED
@@ -65,6 +65,43 @@
65
65
  <table>
66
66
  ```
67
67
 
68
+ ```java
69
+ package com.example.BBS.controller;
70
+
71
+ import com.example.BBS.entity.Entity;
72
+ import com.example.BBS.mapper.BbsMapper;
73
+ import org.springframework.beans.factory.annotation.Autowired;
74
+ import org.springframework.stereotype.Controller;
75
+ import org.springframework.ui.Model;
76
+ import org.springframework.web.bind.annotation.GetMapping;
77
+ import org.springframework.web.bind.annotation.ModelAttribute;
78
+ import org.springframework.web.bind.annotation.RequestMapping;
79
+ import org.springframework.web.bind.annotation.RequestParam;
80
+
81
+ import java.util.List;
82
+
83
+ @Controller
84
+ public class BbsController {
85
+
86
+ @Autowired
87
+ BbsMapper bbsMapper;
88
+
89
+ @RequestMapping(value = "/")
90
+ public String index(Model model){
91
+ List<Entity> list = bbsMapper.selectAll();
92
+ model.addAttribute("submissionDetails", list);
93
+ return "index";
94
+ }
95
+
96
+ @RequestMapping(value = "/add")
97
+ public String add(Entity entity){
98
+ bbsMapper.add(entity);
99
+ return "redirect:/";
100
+ }
101
+ }
102
+
103
+ ```
104
+
68
105
  ### 試したこと
69
106
 
70
107
  SQL文の見直し