forked from YLTeng2653/veggie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseController.java
More file actions
37 lines (30 loc) · 1.05 KB
/
BaseController.java
File metadata and controls
37 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.iiiedu.eeit131.controller;
import org.iiiedu.eeit131.model.Cat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class BaseController {
private static Logger log = LoggerFactory.getLogger(BaseController.class);
@Autowired // DI: Dependency Injection
Cat kitty;
@GetMapping({"/", "/index"})
public String home(Model model) {
log.info("home()方法執行中");
model.addAttribute("myKitty", kitty.toString());
return "index";
}
@GetMapping({"/hello", "/des/sdsd/asa"})
public String hello(
@RequestParam(value="name", required = false) String visitor,
Model model
) {
String message = visitor != null ? visitor + " 您好" : "訪客,您好";
model.addAttribute("helloMessage", message);
return "greeting";
}
}