SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
스프링 3.0 & RESTful

    백기선, 김성윤
봄싹 즐겨찾기 서비스
To Do
•   링크   등록
•   링크   목록 조회
•   링크   조회
•   링크   수정
•   링크   삭제
즐겨찾기 서비스 URL
작업           URL            Method
목록 조회        /link          GET
추가 (폼)       /link/form     GET
추가 (폼 서브밋)   /link          POST
뷰            /link/1        GET
수정 (폼)       /link/1/form   GET
수정 (폼 서브밋)   /link/1        PUT
삭제           /link/1        DELETE
주요 기술 :: 스프링 3.0 @MVC
•   @RequestMapping
•   @PathVariable
•   hiddenMethodFilter
•   스프링 form 태그
•   ContentsNegotiatingViewResolver
@RequestMapping
@RequestMapping(value = ”/link/{id}", method = RequestMethod.DELETE)
  public String delete(@PathVariable int id){
    postService.delete(id);
    return ”/link";
  }



• DefaultAnnotationHandlerMapping이
  @RequestMapping 정보를 참조해서 핸들
  러 찾아줌.
@PathVariable
 @RequestMapping(value = "/link/{id}", method = RequestMethod.GET)
  public String view(@PathVariable int id, Model model){
     model.addAttribute(”link", linkService.get(id));
     return ”link/view";
  }



• /link/1 => /link/{id}
• 기본값 설정 가능
hiddenMethodFilter
<filter>
          <filter-name>httpMethodFilter</filter-name>
          <filter-
class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-
class>
</filter>

<filter-mapping>
          <filter-name>httpMethodFilter</filter-name>
          <url-pattern>/*</url-pattern>
</filter-mapping>

• 기본값: _method
스프링 form 태그
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>


 • form 태그 사용하면 PUT, DELETE 사용시
   자동으로 히든 파라미터로 값 넘겨줌.
<form:form commandName=”link" action=”/link/${link.id}" method="PUT">


<form:form action=”/link/${link.id}" method="DELETE">
ContentsNegotiatingViewResolver
         이게 없다면…
  if ("xml".equals(req.getParameter("type"))) {
    return new ModelAndView(helloMarshallingView, model);
  }
  else {
    return new ModelAndView("/WEB-INF/view/hello.jsp", model);
  }
ContentsNegotiatingViewResolver
         이게 있다면?
ContentsNegotiatingViewResolver
          동작 방식
1. 미디어 타입 결정

2. 뷰 후보 선정

3. 최종 뷰 결정
1. 미디어 타입 결정
1. URL 확장자로 결정
 –   /book.json


2. 요청 파라미터로 결정
 –   /book?format=json


3. Access 헤더 정보로 결정

4. defaultContentType 속성 값 사용.
2. 뷰 후보 선정
1. viewResolvers 미사용시: 서블릿 콘텍스
   트에 등록된 모든 ViewResolver 사용해서
   뷰 후보 선정

2. viewResolvers 사용시: 모든 뷰 리졸버가
   돌려주는 뷰를 후보 목록에 추가

3. defaultView 속성에 설정한 뷰는 무조건
   후보 목록에 추가
3. 최종 뷰 결정
• 미디어 타입과 뷰 목록 비교해서 뷰 결정
 – 뷰의 contents-type과 미디어 타입 비교


• 예제
 – 미디어 타입은 JSON
 – 뷰 후보: JSON 뷰, JSTL 뷰, XML 뷰
 – 결과: JSON뷰 사용
RestTemplate
• Spring 3.0 M2 추가됨.

• Spring’s Template series와 비슷한 형태
 (JdbcTemplate, JmsTemplate ... )

• RESTful 스타일 URL 지원.

• HTTP access 단순화.

• 사용자 정의 콜백 및 결과 추출 클래스 지원.
RestTemplate Hierarchy
RestTemplate methods

HTTP method    RestTemplate methods
GET            getForObject(…)
               getForEntity(…)
POST           postForLocation(…)
               postForObject(…)
PUT            put(…)
DELETE         delete(…)
HEAD           headForHeaders(…)
OPTIONS        optionForAllow(…)
HttpRequests

 SimpleClientHttpRequest
  ( java.net. HttpURLConnection)


CommonsClientHttpRequest
  ( jakarta Commons HttpClient)


 사용자 정의 HttpRequest
HttpMessageConverters
   ByteArray       • application/octet-stream

     String        • text/plain

    Resource       • resource file type

     Source        • text/xml or application/xml

XmlAwareForm       • text/xml or application/xml

Jaxb2RootElement   • text/xml or application/xml

MappingJackson     • application/json

   AtomFeed        • application/atom+xml

   RssChannel      • application/rss+xml
RestTemplate – 사용전
String uri = "http://example.com/hotels/1/bookings";
PostMethod post = new PostMethod(uri);
String request = // create booking request content
post.setRequestEntity(new StringRequestEntity(request));
httpClient.executeMethod(post);
if (HttpStatus.SC_CREATED == post.getStatusCode()) {
    Header location = post.getRequestHeader("Location");
    if (location != null) {
        System.out.println(location.getValue());
    }
}
RestTemplate – 사용후

String uri = "http://example.com/hotels/{id}/bookings";
RestOperations restTemplate = new RestTemplate();
Booking booking = // create booking object
URI location = restTemplate.postForLocation(uri, booking, “1”);
System.out.println(location);
Authentication


Basic Authentication
• CommonsClientHttpRequest


Open Authorization(OAuth)
• 미지원 (3.1M1 Fix 예정)
RestTemplate @ Twitter RESTful

Mais conteúdo relacionado

Mais procurados

Spring boot 5장 cli
Spring boot 5장 cliSpring boot 5장 cli
Spring boot 5장 cliChoonghyun Yang
 
04.실행환경 실습교재(화면처리)
04.실행환경 실습교재(화면처리)04.실행환경 실습교재(화면처리)
04.실행환경 실습교재(화면처리)Hankyo
 
03.실행환경 실습교재(배치처리)
03.실행환경 실습교재(배치처리)03.실행환경 실습교재(배치처리)
03.실행환경 실습교재(배치처리)Hankyo
 
03.실행환경 교육교재(배치처리)
03.실행환경 교육교재(배치처리)03.실행환경 교육교재(배치처리)
03.실행환경 교육교재(배치처리)Hankyo
 
JSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPJSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPMyungjin Lee
 
5-5. html5 connectivity
5-5. html5 connectivity5-5. html5 connectivity
5-5. html5 connectivityJinKyoungHeo
 
Ajax 기술문서 - 김연수
Ajax 기술문서 - 김연수Ajax 기술문서 - 김연수
Ajax 기술문서 - 김연수Yeon Soo Kim
 
02.실행환경 교육교재(데이터처리)
02.실행환경 교육교재(데이터처리)02.실행환경 교육교재(데이터처리)
02.실행환경 교육교재(데이터처리)Hankyo
 
spring.io를 통해 배우는 spring 개발사례
spring.io를 통해 배우는 spring 개발사례spring.io를 통해 배우는 spring 개발사례
spring.io를 통해 배우는 spring 개발사례Daehwan Lee
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿Myungjin Lee
 
5-4. html5 offline and storage
5-4. html5 offline and storage5-4. html5 offline and storage
5-4. html5 offline and storageJinKyoungHeo
 
5-3. html5 device access
5-3. html5 device access5-3. html5 device access
5-3. html5 device accessJinKyoungHeo
 
#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
04.[참고]개발환경 실습교재
04.[참고]개발환경 실습교재04.[참고]개발환경 실습교재
04.[참고]개발환경 실습교재Hankyo
 
실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료
실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료
실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료수홍 이
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs기동 이
 
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처dgmit2009
 

Mais procurados (20)

Spring boot 5장 cli
Spring boot 5장 cliSpring boot 5장 cli
Spring boot 5장 cli
 
04.실행환경 실습교재(화면처리)
04.실행환경 실습교재(화면처리)04.실행환경 실습교재(화면처리)
04.실행환경 실습교재(화면처리)
 
03.실행환경 실습교재(배치처리)
03.실행환경 실습교재(배치처리)03.실행환경 실습교재(배치처리)
03.실행환경 실습교재(배치처리)
 
03.실행환경 교육교재(배치처리)
03.실행환경 교육교재(배치처리)03.실행환경 교육교재(배치처리)
03.실행환경 교육교재(배치처리)
 
JSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPJSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSP
 
5-5. html5 connectivity
5-5. html5 connectivity5-5. html5 connectivity
5-5. html5 connectivity
 
Ajax 기술문서 - 김연수
Ajax 기술문서 - 김연수Ajax 기술문서 - 김연수
Ajax 기술문서 - 김연수
 
Spring boot actuator
Spring boot   actuatorSpring boot   actuator
Spring boot actuator
 
02.실행환경 교육교재(데이터처리)
02.실행환경 교육교재(데이터처리)02.실행환경 교육교재(데이터처리)
02.실행환경 교육교재(데이터처리)
 
spring.io를 통해 배우는 spring 개발사례
spring.io를 통해 배우는 spring 개발사례spring.io를 통해 배우는 spring 개발사례
spring.io를 통해 배우는 spring 개발사례
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿
 
3-2. selector api
3-2. selector api3-2. selector api
3-2. selector api
 
5-4. html5 offline and storage
5-4. html5 offline and storage5-4. html5 offline and storage
5-4. html5 offline and storage
 
5-3. html5 device access
5-3. html5 device access5-3. html5 device access
5-3. html5 device access
 
One-day-codelab
One-day-codelabOne-day-codelab
One-day-codelab
 
#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#17.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
 
04.[참고]개발환경 실습교재
04.[참고]개발환경 실습교재04.[참고]개발환경 실습교재
04.[참고]개발환경 실습교재
 
실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료
실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료
실전! 스프링과 함께하는 환경변수 관리 변천사 발표자료
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
 
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
 

Semelhante a 스프링 3.0 & RESTful

[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVC[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVCAnselmKim
 
vine webdev
vine webdevvine webdev
vine webdevdcfc1997
 
Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Sungjoon Yoon
 
자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)
자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)
자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)DK Lee
 
Atom publishing protocol
Atom publishing protocolAtom publishing protocol
Atom publishing protocolrooya85
 
파이썬 플라스크 이해하기
파이썬 플라스크 이해하기 파이썬 플라스크 이해하기
파이썬 플라스크 이해하기 Yong Joon Moon
 
ASP.NET Web API를 이용한 오픈 API 개발
ASP.NET Web API를 이용한 오픈 API 개발ASP.NET Web API를 이용한 오픈 API 개발
ASP.NET Web API를 이용한 오픈 API 개발SangHoon Han
 
Spring MVC
Spring MVCSpring MVC
Spring MVCymtech
 
HeadFisrt Servlet&JSP Chapter 3
HeadFisrt Servlet&JSP Chapter 3HeadFisrt Servlet&JSP Chapter 3
HeadFisrt Servlet&JSP Chapter 3J B
 
[오픈소스컨설팅]Spring MVC
[오픈소스컨설팅]Spring MVC [오픈소스컨설팅]Spring MVC
[오픈소스컨설팅]Spring MVC Ji-Woong Choi
 
[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우NAVER D2
 
Angular2 router&http
Angular2 router&httpAngular2 router&http
Angular2 router&httpDong Jun Kwon
 
막하는스터디 두번째만남 Express(20151025)
막하는스터디 두번째만남 Express(20151025)막하는스터디 두번째만남 Express(20151025)
막하는스터디 두번째만남 Express(20151025)연웅 조
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문SeungHyun Eom
 
HeadFisrt Servlet&JSP Chapter 13
HeadFisrt Servlet&JSP Chapter 13HeadFisrt Servlet&JSP Chapter 13
HeadFisrt Servlet&JSP Chapter 13J B
 
Servlet jsp 13장
Servlet jsp 13장Servlet jsp 13장
Servlet jsp 13장JeongBong Kim
 
다시보는 Angular js
다시보는 Angular js다시보는 Angular js
다시보는 Angular jsJeado Ko
 

Semelhante a 스프링 3.0 & RESTful (20)

[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVC[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVC
 
vine webdev
vine webdevvine webdev
vine webdev
 
Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)
 
자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)
자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)
자바 웹 개발 시작하기 (3주차 : 스프링 웹 개발)
 
Atom publishing protocol
Atom publishing protocolAtom publishing protocol
Atom publishing protocol
 
파이썬 플라스크 이해하기
파이썬 플라스크 이해하기 파이썬 플라스크 이해하기
파이썬 플라스크 이해하기
 
ASP.NET Web API를 이용한 오픈 API 개발
ASP.NET Web API를 이용한 오픈 API 개발ASP.NET Web API를 이용한 오픈 API 개발
ASP.NET Web API를 이용한 오픈 API 개발
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
HeadFisrt Servlet&JSP Chapter 3
HeadFisrt Servlet&JSP Chapter 3HeadFisrt Servlet&JSP Chapter 3
HeadFisrt Servlet&JSP Chapter 3
 
[오픈소스컨설팅]Spring MVC
[오픈소스컨설팅]Spring MVC [오픈소스컨설팅]Spring MVC
[오픈소스컨설팅]Spring MVC
 
Html5
Html5 Html5
Html5
 
[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우
 
Angular2 router&http
Angular2 router&httpAngular2 router&http
Angular2 router&http
 
막하는스터디 두번째만남 Express(20151025)
막하는스터디 두번째만남 Express(20151025)막하는스터디 두번째만남 Express(20151025)
막하는스터디 두번째만남 Express(20151025)
 
4-3. jquery
4-3. jquery4-3. jquery
4-3. jquery
 
HTTP web server 구현
HTTP web server 구현HTTP web server 구현
HTTP web server 구현
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문
 
HeadFisrt Servlet&JSP Chapter 13
HeadFisrt Servlet&JSP Chapter 13HeadFisrt Servlet&JSP Chapter 13
HeadFisrt Servlet&JSP Chapter 13
 
Servlet jsp 13장
Servlet jsp 13장Servlet jsp 13장
Servlet jsp 13장
 
다시보는 Angular js
다시보는 Angular js다시보는 Angular js
다시보는 Angular js
 

Mais de JavaCommunity.Org

안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 API안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 APIJavaCommunity.Org
 
안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처JavaCommunity.Org
 
이클립스와 안드로이드
이클립스와 안드로이드이클립스와 안드로이드
이클립스와 안드로이드JavaCommunity.Org
 
Jetty Continuation - 이상민
Jetty Continuation - 이상민Jetty Continuation - 이상민
Jetty Continuation - 이상민JavaCommunity.Org
 
결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점JavaCommunity.Org
 
E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발JavaCommunity.Org
 

Mais de JavaCommunity.Org (7)

안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 API안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 API
 
안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처
 
이클립스와 안드로이드
이클립스와 안드로이드이클립스와 안드로이드
이클립스와 안드로이드
 
Jetty Continuation - 이상민
Jetty Continuation - 이상민Jetty Continuation - 이상민
Jetty Continuation - 이상민
 
결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점
 
E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발
 
RESTful Java
RESTful JavaRESTful Java
RESTful Java
 

Último

MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionKim Daeun
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Kim Daeun
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Wonjun Hwang
 
Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Wonjun Hwang
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스
 
A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)Tae Young Lee
 

Último (6)

MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)
 
Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차
 
A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)
 

스프링 3.0 & RESTful

  • 1. 스프링 3.0 & RESTful 백기선, 김성윤
  • 3. To Do • 링크 등록 • 링크 목록 조회 • 링크 조회 • 링크 수정 • 링크 삭제
  • 4. 즐겨찾기 서비스 URL 작업 URL Method 목록 조회 /link GET 추가 (폼) /link/form GET 추가 (폼 서브밋) /link POST 뷰 /link/1 GET 수정 (폼) /link/1/form GET 수정 (폼 서브밋) /link/1 PUT 삭제 /link/1 DELETE
  • 5. 주요 기술 :: 스프링 3.0 @MVC • @RequestMapping • @PathVariable • hiddenMethodFilter • 스프링 form 태그 • ContentsNegotiatingViewResolver
  • 6. @RequestMapping @RequestMapping(value = ”/link/{id}", method = RequestMethod.DELETE) public String delete(@PathVariable int id){ postService.delete(id); return ”/link"; } • DefaultAnnotationHandlerMapping이 @RequestMapping 정보를 참조해서 핸들 러 찾아줌.
  • 7. @PathVariable @RequestMapping(value = "/link/{id}", method = RequestMethod.GET) public String view(@PathVariable int id, Model model){ model.addAttribute(”link", linkService.get(id)); return ”link/view"; } • /link/1 => /link/{id} • 기본값 설정 가능
  • 8. hiddenMethodFilter <filter> <filter-name>httpMethodFilter</filter-name> <filter- class>org.springframework.web.filter.HiddenHttpMethodFilter</filter- class> </filter> <filter-mapping> <filter-name>httpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> • 기본값: _method
  • 9. 스프링 form 태그 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> • form 태그 사용하면 PUT, DELETE 사용시 자동으로 히든 파라미터로 값 넘겨줌. <form:form commandName=”link" action=”/link/${link.id}" method="PUT"> <form:form action=”/link/${link.id}" method="DELETE">
  • 10. ContentsNegotiatingViewResolver 이게 없다면… if ("xml".equals(req.getParameter("type"))) { return new ModelAndView(helloMarshallingView, model); } else { return new ModelAndView("/WEB-INF/view/hello.jsp", model); }
  • 11. ContentsNegotiatingViewResolver 이게 있다면?
  • 12. ContentsNegotiatingViewResolver 동작 방식 1. 미디어 타입 결정 2. 뷰 후보 선정 3. 최종 뷰 결정
  • 13. 1. 미디어 타입 결정 1. URL 확장자로 결정 – /book.json 2. 요청 파라미터로 결정 – /book?format=json 3. Access 헤더 정보로 결정 4. defaultContentType 속성 값 사용.
  • 14. 2. 뷰 후보 선정 1. viewResolvers 미사용시: 서블릿 콘텍스 트에 등록된 모든 ViewResolver 사용해서 뷰 후보 선정 2. viewResolvers 사용시: 모든 뷰 리졸버가 돌려주는 뷰를 후보 목록에 추가 3. defaultView 속성에 설정한 뷰는 무조건 후보 목록에 추가
  • 15. 3. 최종 뷰 결정 • 미디어 타입과 뷰 목록 비교해서 뷰 결정 – 뷰의 contents-type과 미디어 타입 비교 • 예제 – 미디어 타입은 JSON – 뷰 후보: JSON 뷰, JSTL 뷰, XML 뷰 – 결과: JSON뷰 사용
  • 16.
  • 17. RestTemplate • Spring 3.0 M2 추가됨. • Spring’s Template series와 비슷한 형태 (JdbcTemplate, JmsTemplate ... ) • RESTful 스타일 URL 지원. • HTTP access 단순화. • 사용자 정의 콜백 및 결과 추출 클래스 지원.
  • 19. RestTemplate methods HTTP method RestTemplate methods GET getForObject(…) getForEntity(…) POST postForLocation(…) postForObject(…) PUT put(…) DELETE delete(…) HEAD headForHeaders(…) OPTIONS optionForAllow(…)
  • 20. HttpRequests SimpleClientHttpRequest ( java.net. HttpURLConnection) CommonsClientHttpRequest ( jakarta Commons HttpClient) 사용자 정의 HttpRequest
  • 21. HttpMessageConverters ByteArray • application/octet-stream String • text/plain Resource • resource file type Source • text/xml or application/xml XmlAwareForm • text/xml or application/xml Jaxb2RootElement • text/xml or application/xml MappingJackson • application/json AtomFeed • application/atom+xml RssChannel • application/rss+xml
  • 22. RestTemplate – 사용전 String uri = "http://example.com/hotels/1/bookings"; PostMethod post = new PostMethod(uri); String request = // create booking request content post.setRequestEntity(new StringRequestEntity(request)); httpClient.executeMethod(post); if (HttpStatus.SC_CREATED == post.getStatusCode()) { Header location = post.getRequestHeader("Location"); if (location != null) { System.out.println(location.getValue()); } }
  • 23. RestTemplate – 사용후 String uri = "http://example.com/hotels/{id}/bookings"; RestOperations restTemplate = new RestTemplate(); Booking booking = // create booking object URI location = restTemplate.postForLocation(uri, booking, “1”); System.out.println(location);
  • 24. Authentication Basic Authentication • CommonsClientHttpRequest Open Authorization(OAuth) • 미지원 (3.1M1 Fix 예정)