본문 바로가기
Programming/Spring

[spring] @pathVariable 사용설정및 사용하기

by 막이 2015. 6. 10.

참고url

http://xens.tistory.com/237

http://georgovassilis.blogspot.kr/2012/03/spring-pathvariable-mapping-incomplete.html



web.xml

<servlet-mapping>

<servlet-name>appServlet</servlet-name>

<!-- <url-pattern>*.do</url-pattern> --> 수정전

<url-pattern>/</url-pattern> -->수정후   ( 여기때문에 되게 고생했다.. 설정안하면404 떨어진다.. )

</servlet-mapping>



servlet-context.xml

<!-- spring @pathVariable사용하려면 설정 -->

<beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMet            hodHandlerAdapter">

    <beans:property name="alwaysUseFullPath" value="true" />

</beans:bean>

<beans:bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotati            onHandlerMapping">

      <beans:property name="alwaysUseFullPath" value="true" />

</beans:bean>



controller

@RequestMapping(value="/board/{seq}", method=RequestMethod.GET)

public ModelAndView boardSeq(@PathVariable("seq")String seq )throws Exception{

try{

logger.info("seq(get) :"+seq);

return new ModelAndView("/board/board.tiles");

}catch(Exception e){

logger.error(e.getMessage());

e.printStackTrace();

return new ModelAndView("/error.tiles");

}

}


@RequestMapping(value ="/board") 

public ModelAndView board(BoardVO boardVO, HttpServletRequest request, HttpServletResponse response)throws Exception{

try{

List<BoardVO> list = boardDaoImpl.selectBbs();

return new ModelAndView("/board/board.tiles","list",list);

}catch(Exception e){

logger.error(e.getMessage());

e.printStackTrace();

return new ModelAndView("/error.tiles");

}

}


요청 url ==> 

http://localhost:8080/board/seee ->  바로위 처음 controller

http://localhost:8080/board    ->바로위두번째 controller