아디봉의.net
[spring] @pathVariable 사용설정및 사용하기 본문
테스트일 : 2014/01/21
환경 spring + mybatis + 부트스트랩 이정도되겠다.. (부가적으로 tiles, log4j등사용)
1) 설정 - 설정이 전혀 안되어 있던 상태이며 삽질좀 많이 했다...따라하면 다들 될것이다 ;;
참고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