Spring - SpringÀÇ Controllerµé. 1.AbastractCommandController
¼Ò°³
AbstractCommandController´Â ÆäÀÌÁöÀÇ ³Ñ¾î¿À´Â ÆĶó¹ÌÅ͵éÀ» bean °´Ã¼¿¡ ÀÚµ¿¸ÊÇÎÀÌ µÇ¾î Controller ¿¡¼ »ç¿ë ÇÒ ¼ö ÀÖ°Ô ¸¸µå´Â ¿ªÇÒÀ» ÇÑ´Ù.
Áï
jsp ÆäÀÌÁöÀÇ È¸¿ø°¡ÀÔÆäÀÌÁö ¿¡¼ ÆĶó¹ÌÅÍ·Î name,age... µîµîÀÌ ³Ñ¾î¿À¸é ¼±¾ðÇÑ beanÀÇ propertyÀÎ String name, String age¿¡ ´ëÀÀµÇ¾î ÀÚµ¿ ÀúÀåÀÌ µÈ´Ù.
»ç¿ë¹æ¹ý
DI¸¦ ¼±¾ðÇÑ xml ÆÄÀÏ¿¡¼ Á÷Á¢ beanÀÇ Å¬·¡½º°æ·ÎÀÎ "commandClass" ¿Í commandClassÀÇ À̸§ÀÎ "commandName" À» ÆĶó¹ÌÅÍ·Î ³Ñ°ÜÁÖ¾î¾ß ÇÑ´Ù.
¿¹)
<bean id="listAbstractCommandController"
class="kr.co.springboard.controllers.ListAbstractCommandController">
<property name="commandName" value="boardBean"/>
<property name="boardService" ref="boardService"/>
<property name="viewName" value="boardList"/>
</bean>
ÀÌ·¸°Ô property ·Î ¼³Á¤ÇÏ´Â ¹æ¹ýÀÌ Àִ°¡ Çϸé Á÷Á¢ AbstractCommandController¸¦ È®ÀåÇÑ Å¬·¡½º¿¡¼ ´ÙÀ½°ú °°ÀÌ Contructor¸¦ ±¸ÇöÇصµ µÈ´Ù.
public ListAbstractCommandController(){
setCommandClass(BoardBean.class);
setCommandName("boardBean");
}
À§ÀÇ 2°¡Áö ¹æ¹ýÀ¸·Î ¼±¾ðÇϸé AbstractCommandControllerÀÇ handle() method¸¦ ÅëÇؼ Àü´Þ ÀÎÀÚÀÎ command¸¦ ÅëÇØ Àü¼ÛµÈ µ¥ÀÌÅ͸¦ ¹ÞÀ» ¼ö ÀÖ´Ù.
protected ModelAndView handle(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
ModelAndView mnv = new ModelAndView();
BoardBean boardBean = (BoardBean)command;
BoardDTO dto = new BoardDTO();
dto.setNowPage(boardBean.getNowPage());
if(dto.getNowPage() == 0){
dto.setNowPage(1);
}
dto.setTotalCount(boardService.boardTotalCount(dto));
dto = (BoardDTO)PagingUtil.setPagingInfo(dto);
List<BoardDTO> boardList = this.boardService.boardList(dto);
mnv.setViewName(viewName);
mnv.addObject("boardList", boardList);
mnv.addObject("dto",dto);
return mnv;
}
À§¿Í °°ÀÌ »ý¼ºÀÚ,ȤÀº xml¹®¼ÀÇ property ·Î ¼¼ÆÃÇØÁØ commandClass¿Í commandName Àº handle() ¸Þ¼ÒµåÀÇ command object¸¦ ÅëÇØ µ¥ÀÌÅ͸¦ Àü´Þ ¹Þ±â ¶§¹®¿¡ command instance¸¦ »ý¼ºÇØ ÁÖ´Â ¿ªÇÒÀ» ÇÑ´Ù.
ÀÌ·¸°Ô Àü´ÞµÈ command °´Ã¼¸¦ ¿øÇÏ´Â ÇüÀ¸·Î Çüº¯È¯À» Çؼ »ç¿ëÇÏ¸é µÈ´Ù.