멤버 클래스의(Member) 속성에 아래와 같이 데이터를 저장해서 화면에 출력해 보세요.
더보기
package com.example.controllerexam.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* packageName : com.example.controllerexam.model
* fileName : Member
* author : L.DH
* date : 2023-10-05
* description : 회원 클래스
* 요약 :
* <p>
* ===========================================================
* DATE AUTHOR NOTE
* ———————————————————————————————
* 2023-10-05 L.DH 최초 생성
*/
// TODO : Lombok 라이브러리 : 유용한 @ 모은 라이브러리
// @Setter : setter 함수를 만들어주는 어노테이션
// @Getter : getter 함수를 만들어주는 어노테이션
// @ToString : toString 재정의 함수 자동으로 만들어주는 어노테이션
// @AllArgsConstructor : 모든 속성을 가진 생성자 자동 정의
@Setter
@Getter
@ToString
@AllArgsConstructor
public class Member {
// TODO : 속성, 생성자, 함수(getter/setter)
String id; // 회원 id
String name; // 회원명
}
더보기
package com.example.controllerexam.controller.exam06;
import com.example.controllerexam.model.Member;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* packageName : com.example.controllerexam.controller.exam06
* fileName : MultiPathRestController
* author : L.DH
* date : 2023-10-06
* description : @PathVariable, @RestController
* 요약 :
*
* @Controller : jsp 개발 시 사용
* => return 값 : 이동할 jsp 페이지명
* @RestController : react / vue 연동 개발 시 사용
* => return 값 : json 데이터로 출력됨 : {속성: 값}
* <p>
* ===========================================================
* DATE AUTHOR NOTE
* ———————————————————————————————
* 2023-10-06 L.DH 최초 생성
*/
@RestController
@RequestMapping("/exam06")
public class MultiPathRestController {
// TODO: http://localhost:8000/exam06/multi-path-rest/id/hong/name/홍길동
@GetMapping("/multi-path-rest/id/{id}/name/{name}")
public Member getMultiPath(@PathVariable String id, @PathVariable String name) {
// 멤버 객체 생성
Member member = new Member(id, name);
// 결과 json 데이터로 전송
return member;
}
}
연습1) 부서 클래스의(Dept) 속성에 아래와 같이 데이터를 저장해서 화면에 출력해 보세요.
+ 레스트 클라이언트에 출력해 보세요.
Rest Client 이용해서 Rest API 함수를 테스트하는 것
더보기
package com.example.controllerexam.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* packageName : com.example.controllerexam.model
* fileName : Dept
* author : GGG
* date : 2023-10-05
* description : 부서 클래스
* 요약 :
* <p>
* ===========================================================
* DATE AUTHOR NOTE
* —————————————————————————————
* 2023-10-05 GGG 최초 생성
*/
// TODO: Lombok 라이브러리 : 유용한 @ 모은 라이브러리
// @Setter : setter 함수를 만들어주는 어노테이션
// @Getter : getter 함수를 만들어주는 어노테이션
// @ToString : toString 재정의 함수 자동으로 만들어주는 어노테이션
// @AllArgsConstructor : 모든 속성을 가진 생성자 자동 정의
@Setter
@Getter
@ToString
@AllArgsConstructor
public class Dept {
int dno; // 부서번호
String dname; // 부서명
String loc; // 부서위치
}
더보기
package com.example.controllerexam.controller.exam06;
import com.example.controllerexam.model.Dept;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* packageName : com.example.controllerexam.controller.exam06
* fileName : MultiPathRestController
* author : L.DH
* date : 2023-10-06
* description : @PathVariable, @RestController
* 요약 :
*
* @Controller : jsp 개발 시 사용
* => return 값 : 이동할 jsp 페이지명
* @RestController : react / vue 연동 개발 시 사용
* => return 값 : json 데이터로 출력됨 : {속성: 값}
* <p>
* ===========================================================
* DATE AUTHOR NOTE
* ———————————————————————————————
* 2023-10-06 L.DH 최초 생성
*/
@RestController
@RequestMapping("/exam06")
public class MultiPathRestController {
// TODO: 연습1) 부서 클래스의(Dept) 속성에 아래와 같이
// 데이터를 저장해서 화면에 출력해 보세요.
// 결과 :
// {
// "dno": 10,
// "loc": "Seoul",
// "dname": "Sales"
// }
// Rest Client 이용해서 Rest API 함수를 테스트하는 것
@GetMapping("/example01-dept/dno/{dno}/dname/{dname}/loc/{loc}")
// TODO: http://localhost:8000/exam06/example01-dept/dno/10/dname/Seoul/loc/Sales
public Dept getExample01(
@PathVariable int dno,
@PathVariable String dname,
@PathVariable String loc
) {
// 객체 생성
Dept dept = new Dept(dno, dname, loc);
// 결과 json 데이터로 전송
return dept;
}
}
연습2) 게시판(Board) 모델 클래스를 만들어서// 아래와 같이 출력되도록 레스트 클라이언트에 출력해 보세요.
더보기
package com.example.controllerexam.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* packageName : com.example.controllerexam.model
* fileName : Board
* author : L.DH
* date : 2023-10-06
* description :
* 요약 :
* <p>
* ===========================================================
* DATE AUTHOR NOTE
* ———————————————————————————————
* 2023-10-06 L.DH 최초 생성
*/
@Setter
@Getter
@ToString
@AllArgsConstructor
public class Board {
long no; // 넘버
String title; // 제목
String content; // 내용
String count; // 조회수
}
더보기
package com.example.controllerexam.controller.exam06;
import com.example.controllerexam.model.Board;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* packageName : com.example.controllerexam.controller.exam06
* fileName : MultiPathRestController
* author : L.DH
* date : 2023-10-06
* description : @PathVariable, @RestController
* 요약 :
*
* @Controller : jsp 개발 시 사용
* => return 값 : 이동할 jsp 페이지명
* @RestController : react / vue 연동 개발 시 사용
* => return 값 : json 데이터로 출력됨 : {속성: 값}
* <p>
* ===========================================================
* DATE AUTHOR NOTE
* ———————————————————————————————
* 2023-10-06 L.DH 최초 생성
*/
@RestController
@RequestMapping("/exam06")
public class MultiPathRestController {
// TODO: 연습2) 게시판(Board) 모델 클래스를 만들어서
// 아래와 같이 출력되도록 레스트 클라이언트에 출력해 보세요.
// 결과 :
// {
// "no": 10,
// "title": "제목",
// "content": "내용",
// "count" : "1"
// }
@GetMapping("/example02-board/no/{no}/title/{title}/content/{content}/count/{count}")
public Board getBoard(
@PathVariable long no,
@PathVariable String title,
@PathVariable String content,
@PathVariable String count
) {
// 객체 생성
Board board = new Board(no, title, content, count);
// 결과 json 데이터로 전송
return board;
}
}
'Spring Boot' 카테고리의 다른 글
[SpringBoot] CRUD (1) | 2023.10.10 |
---|---|
[SpringBoot] 로그백, 로깅 라이브러리 logback , log4jdbc 설정 (0) | 2023.10.06 |
[SpringBoot] 데이터를 입력받아(insert) 화면에 출력하기 (0) | 2023.10.06 |
[SpringBoot] Jsp library 사용법 (0) | 2023.10.06 |
[SpringBoot] 매개변수(파라메터) 전달받아 출력하기 (0) | 2023.10.05 |