반응형
@RestController 시작 전 준비과정이 궁금하다면?↓↓↓↓↓
https://maxtime1004.tistory.com/80
MemberVO
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
38
39
40
41
42
43
|
package com.myspring.pro29.ex01;
public class MemberVO {
private String id;
private String pwd;
private String name;
private String email;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "MemberVO [id=" + id + ", pwd=" + pwd +
", name=" + name + ", email=" + email + "]";
}
}
|
cs |
TestController
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package com.myspring.pro29.ex01;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test/*")
public class TestController {
@RequestMapping("/hello")
public String hello() {
return "Hello REST!!!";
}
@RequestMapping("/member")
public MemberVO member() {
MemberVO vo= new MemberVO();
vo.setId("hong");
vo.setPwd("1234");
vo.setName("홍길동");
vo.setEmail("hong@naver.com");
return vo;
}
@RequestMapping("/membersList")
public List<MemberVO> listMembers(){
List<MemberVO> list = new ArrayList<MemberVO>();
for(int i=0; i<10; i++) {
MemberVO vo= new MemberVO();
vo.setId("hong" + i);
vo.setPwd("123" + i);
vo.setName("홍길동" + i);
vo.setEmail("hong" + i + "@naver.com");
list.add(vo);
}
return list;
}
@RequestMapping("/membersMap")
public Map<Integer, MemberVO> membersMap(){
Map<Integer, MemberVO> map = new HashMap<Integer, MemberVO>();
for(int i=0; i<10; i++) {
MemberVO vo= new MemberVO();
vo.setId("hong" + i);
vo.setPwd("123" + i);
vo.setName("홍길동" + i);
vo.setEmail("hong" + i + "@naver.com");
map.put(i, vo);
}
return map;
}
}
|
cs |
List 객체 전달 화면
Map 객체 전달 화면
반응형
'코딩 기록 > JSP' 카테고리의 다른 글
[JSP] @RequestBody와 @Response 사용하기 (0) | 2021.05.28 |
---|---|
[JSP] @PathVariable 사용하기 (0) | 2021.05.28 |
[JSP] @RestController 이용해 VO 객체 전달하기 (0) | 2021.05.27 |
[JSP] @RestController 문자열 전달하기 (0) | 2021.05.27 |
[JSP] REST 란? (0) | 2021.05.27 |