Controller
url 에 해당하는 파일로 연결해주는 얘
★
어노테이션 | 설명 | return 값 |
@Controller | jsp 개발시 사용 | 이동할 jsp 페이지 명 |
@RestController | react / vue 연동 개발시 사용 | json 데이터로 출력됨 {속성 : 값} 예시 ) Member 객체 등 |
정의
@Controller
클래스에 컨트롤러 기능을 부여
@Controller
public class 클래스명 {}
정의
@RestController
return 값이 좀 달라지는 것 빼고 괜참음
https://tinylittlelife.tistory.com/206
@RestController
public class 클래스명 {}
< 1 >
공통
( 단, RestMapping 은 리턴 형식이 다르다 )
↓
@GetMapping
( get 방식 : 조회요청 )
( @PostMapping 등 post , put , delete 방식도 가능 )
url이 웹브라우저 주소창에 입력되면 페이지가 화면에 출력
@GetMapping("url")
public String 함수() { return "보여줄 페이지명"; }
@PostMapping
( post 방식 : insert 요청 )
( : 데이터 저장 요청 )
@PostMapping("url")
@PutMapping
( put 방식 : update 요청 )
( : 데이터 수정 요청 )
@PutMapping("url")
@DeleteMapping
( delete 방식 : delete 요청 )
( : 데이터 삭제 요청 )
@DeleteMapping("url")
@RequestParam
Parameter 값 받아오기 (쿼리스트링 방식)
https://tinylittlelife.tistory.com/193
@GetMapping("경로")
함수명(Model model , @RequestParam(defaultValue="") String 변수명) {
model.addAttribute("key" , 변수명)
return "페이지";
}
@PathVariable
파라메터 방식 매개변수 전달하는 어노테이션
https://tinylittlelife.tistory.com/199
@GetMapping("경로/{웹매개변수명}")
public String 함수명(Model model , @PathVarialbe String 웹매개변수명) {
model.addAttribute("key",웹매개변수명);
return "페이지명";
}
@RequestMapping
URL 중복을 줄여줌
( 공통 url 함수의 url 과 합쳐져서 사용됨 )
참조 주소
https://mungto.tistory.com/436
@RequestMapping("공통 url")
public class 클래스명
@ModelAttribute
( jsp에서 사용 / react 등 은 RequestBody 사용 )
객체의 속성명으로 jsp로 각각 전달
https://tinylittlelife.tistory.com/198
@GetMapping("경로")
public String 함수명(@ModelAttribute 클래스명 변수) {
return "페이지명";
}
@ResponseBody
함수의 결과로 json 데이터를 리턴하고자 할때 사용하는 어노테이션
( RestController가 붙어 있으면 @ResponseBody가 따라오기 때문에 않붙여도 됨 )
https://tinylittlelife.tistory.com/213
@PostMapping("경로")
@ResponseBody
public List<객체명> 함수명() {
return ;
}
@Slf4j
로깅 라이브러리
( 디버그 할 때 필요 )
https://tinylittlelife.tistory.com/211
@Slf4j
public class 클래스명 {}
log.debug(값); <- 사용
( 클래스 )
RedirectView
view 페이지 강제 이동
( 페이지를 Redirect 시킴 )
( Form 태그에 관한 예제가 있습니다. )
https://tinylittlelife.tistory.com/214
return new RedirectView("페이지경로");
< 2 >
RestController
↓
@RequestBody
요청 본문(request body)에 담긴 값을 자바 객체로 변환 (conversion)
( PostMapping 와 함께 많이 사용 )
https://tinylittlelife.tistory.com/207
@PostMapping("url")함수명(@RequestBody 객체명)
( 클래스 )
ResponseEntity
ResponseEntity는 사용자의 HttpRequest에 대한 응답 데이터를 포함하는 클래스이다.
https://tinylittlelife.tistory.com/208
new ResponseEntity<>(신호);
new ResponseEntity<>(배열[객체] , 신호);
'SpringBoot' 카테고리의 다른 글
윈도우 카프카 - Kafka 를 Springboot 에서 간단히 써보자 (1) | 2023.12.12 |
---|---|
MySQL + Springboot JPA + logback (1) | 2023.12.12 |
SpringBoot - MyBatis (RestController) (0) | 2023.10.16 |
SpringBoot - SSR , SCR (개념 간략) (0) | 2023.10.04 |
SpringBoot - 시작 (0) | 2023.10.04 |