forked from cho-log/spring-learning-test
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMemberController.java
More file actions
33 lines (28 loc) · 1.19 KB
/
MemberController.java
File metadata and controls
33 lines (28 loc) · 1.19 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
package cholog;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MemberController {
@GetMapping("/hello")
public String world(@RequestParam(name = "name", required = false) String name, Model model) {
// TODO: /hello 요청 시 resources/templates/static.html 페이지가 응답할 수 있도록 설정하세요.
// TODO: 쿼리 파라미터로 name 요청이 들어왔을 때 해당 값을 hello.html에서 사용할 수 있도록 하세요.
if (name == null){
// 쿼리 파라미터가 없는 경우
return "static";
} else {
// 쿼리 파라미터가 있는 경우.
model.addAttribute("name", name);
return "hello";
}
}
@GetMapping("/json")
@ResponseBody
public Person json() {
// TODO: /json 요청 시 {"name": "brown", "age": 20} 데이터를 응답할 수 있도록 설정하세요.
return new Person("brown", 20);
}
}