일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 리브레캐드
- MSSQL
- 오라클
- tomcat
- 운정
- 강좌
- html5
- 예제
- mysql
- 파주
- 코딩
- 톰캣
- oracle
- librecad
- Spring Security
- 안드로이드
- 설정
- 유니티
- jobtoy
- 시작하기
- 설치
- 라즈베리파이
- 스크래치
- 잡토이 메이킹 코딩 학원
- jsp
- Unity
- 아두이노
- Android
- 잡토이
- s4a
- Today
- Total
랩제이
[spring framework] Spring3에 @PathVariable 을 이용하여 REST 방식의 url을 적용 본문
[spring framework] Spring3에 @PathVariable 을 이용하여 REST 방식의 url을 적용
labj 2012. 10. 30. 14:29[spring framework] Spring3에 @PathVariable 을 이용하여 REST 방식의 url을 적용
Rest 방식으로 url을 지정할 경우에
게시판의 경우 http://~/board/[관리자ID]/[게시물ID] 호출하면 내용을 볼 수 있도록 될 것입니다.
컨텐츠 관리의 경우 http://~/contents/[컨텐츠ID] 호출하면 내용을 볼 수 있도록 될 것입니다.
기존 프로젝트에(YUL_ICLIB) 추가된 소스입니다.
1. spring-context.xml 추가
<!-- 어노테이션 스캔 설정-->
<context:component-scan base-package="*" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:alwaysUseFullPath="true" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" p:alwaysUseFullPath="true" />
2. springmvc-context.xml
<!--
- 인터셉터 추가
-->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="alwaysUseFullPath" value="true" />
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name="alwaysUseFullPath" value="true" />
</bean>
3. web.xml 추가
<filter-mapping>
<filter-name>authenticationFilter</filter-name>
<url-pattern>*.do</url-pattern>
<url-pattern>*.jsp</url-pattern>
<url-pattern>/board/*</url-pattern>
</filter-mapping>
<!-- 스프링 mvc 적용 URL -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
<url-pattern>*.static</url-pattern>
<url-pattern>/board/*</url-pattern>
</servlet-mapping>
4. @Controller (kr.actsoft.yul.board.web. BoardCtrl) 함수
@RequestMapping(value = "/board/view/{manageIdx}/{boardIdx}")
public ModelAndView boardView1(@PathVariable("manageIdx") String manageIdx, @PathVariable("boardIdx") String boardIdx, ModelMap model) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("boardIdx", boardIdx);
resultMap.put("manageIdx", manageIdx);
String resultURL = "board/view";
return new ModelAndView(resultURL, "resultMap", resultMap);
}
[spring framework] Spring3에 @PathVariable 을 이용하여 REST 방식의 url을 적용
'programming > spring_framework' 카테고리의 다른 글
[SpringFramework] Spring 3 적용하기 (0) | 2012.10.22 |
---|---|
spring framework tomcat 6 JNDI 연결 예제 (0) | 2012.05.08 |
스프링mvc에서 언어 변경하기 (0) | 2012.03.21 |
스프링프레임워크 버전 확인하기 (0) | 2012.03.21 |
Spring Framework 구조도 (0) | 2012.03.21 |