일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- mocking
- AJIT
- Recoil
- 타입 단언
- Custom Hook
- CS
- zustand
- docker
- Headless 컴포넌트
- Compound Component
- 클라이언트 상태 관리 라이브러리
- prettier-plugin-tailwindcss
- JavaScript
- 명시적 타입 변환
- 프로세스
- Microtask Queue
- 25년 2월
- jotai
- react
- 회고
- linux 배포판
- 좋은 PR
- helm-chart
- Sparkplug
- msw
- Render Queue
- TypeScript
- type assertion
- 암묵적 타입 변환
- useLayoutEffect
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발생
}