일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Microtask Queue
- 클라이언트 상태 관리 라이브러리
- TypeScript
- Sparkplug
- zustand
- 프로세스
- CS
- 암묵적 타입 변환
- prettier-plugin-tailwindcss
- jotai
- 주니어개발자
- 회고
- Compound Component
- Redux Toolkit
- Render Queue
- react
- Custom Hook
- task queue
- AJIT
- useLayoutEffect
- 좋은 PR
- 타입 단언
- Headless 컴포넌트
- JavaScript
- helm-chart
- Recoil
- type assertion
- 명시적 타입 변환
- docker
- linux 배포판
Archives
- Today
- Total
구리
[Spring] @ResponseBody, MessageConverter 본문
Controller에서 String이 반환되면 view 이름을 찾아서 JSP를 렌더링 하고, view가 없으면 404를 반환합니다
@RequestMapping("getBoard.do")
public String getBoard() {
return "board";
}
만약 method에 @ResponseBody 어노테이션이 적용되어 있다면 view를 찾지 않고, String 값을 그대로 반환합니다.
@ResponseBody @RequestMapping("getBoard.do")
public String getBoard(BoardVO vo) throws Exception {
return boardService.getBoard(vo);
}
Dispatcher Servlet이 ModelAndView를 반환하면 ViewResolver가 실행됩니다.
@RequestMapping("main")
public ModelAndView getBoard(ModelAndView mav) throws Exception {
mav.setViewName("board");
return mav;
}
@ResponseBody가 있으면 View 경로가 아닌 HTTP Response Body에 직접 출력되기에 MessageConverter가 실행되어 변환이 이뤄진 후 반환됩니다.
@ResponseBody @RequestMapping("getBoard.do")
public Object getBoard(BoardVO vo) throws Exception {
return boardService.getBoard(vo);
}
@ResponseBody가 있으면 MessageConverter가 실행되는데 null을 던지면 처리할 객체가 없어서 error가 발생합니다
@ResponseBody @RequestMapping("error")
public Object error() throws Exception {
return null; // error발생
}