teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

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

2018/11/15 04:10

投稿

G-ym
G-ym

スコア16

title CHANGED
File without changes
body CHANGED
@@ -184,4 +184,41 @@
184
184
 
185
185
  }
186
186
 
187
+ ```
188
+ ```java
189
+ import java.util.List;
190
+
191
+ import org.springframework.beans.factory.annotation.Autowired;
192
+ import org.springframework.stereotype.Controller;
193
+ import org.springframework.ui.Model;
194
+ import org.springframework.web.bind.annotation.GetMapping;
195
+ import org.springframework.web.bind.annotation.PostMapping;
196
+
197
+ import com.example.demo.login.domain.model.User;
198
+ import com.example.demo.login.domain.service.UserService;
199
+
200
+ @Controller
201
+ public class HomeController {
202
+ @Autowired
203
+ UserService userService;
204
+
205
+ @GetMapping("/home")
206
+ public String getHome(Model model) {
207
+ model.addAttribute("contents","home/home :: home_contents");
208
+ return "home/homeLayout";
209
+ }
210
+ @PostMapping("/logout")
211
+ public String posthome() {
212
+ return"redirect:/login";
213
+ }
214
+
215
+ @GetMapping("/userList")
216
+ public String getUserList(Model model) {
217
+ model.addAttribute("contents","home/userList :: userList_contents");
218
+ List<User> userList = userService.selectMany();
219
+ model.addAttribute("userList",userList);
220
+ return "home/userList";
221
+ }
222
+ }
223
+
187
224
  ```