REST API - @RestController
·
Spring
1. @RestController란?@RestController는 Spring MVC에서 RESTful 웹 서비스를 개발하기 위해 사용하는 어노테이션입니다.기존의 @Controller와 @ResponseBody의 조합을 대체하여, 더 간결하게 RESTful API를 개발할 수 있습니다.2. @RestController 특징RESTful 응답 처리:메서드의 반환 값이 뷰(view) 이름이 아닌 **HTTP 응답 본문(body)**에 직렬화되어 클라이언트로 전달.JSON, XML, 텍스트 등 다양한 포맷으로 응답 가능.자동 직렬화 지원:반환 객체를 JSON, XML로 변환하여 HTTP 응답 본문에 포함.Spring Boot에서는 기본적으로 Jackson 라이브러리를 사용하여 JSON으로 직렬화.간결한 코드:..
REST API - XML과 JSON
·
Spring
XML (eXtensible Markup Language)XML은 데이터를 저장하고 교환하기 위한 마크업 언어로, 사람이 읽기 쉽고 기계가 해석하기 쉬운 형식.1998년 W3C 표준으로 제정.데이터를 계층적(트리 구조)으로 표현.XML 예제 1 홍길동 hong@example.comJSON (JavaScript Object Notation)JSON은 데이터를 저장하고 교환하기 위한 경량 데이터 포맷으로, 객체 표기법을 기반으로 한 단순한 구조.2001년 Douglas Crockford가 설계.데이터를 키-값 쌍으로 표현.JSON 예제{ "id": 1, "name": "홍길동", "email": "hong@example.com"}XML과 JSON의 주요 비교항목XMLJSON구..
REST API - 개요
·
Spring
1. REST API란?1.1 REST란?REST(Representational State Transfer)는 웹 서비스 설계 아키텍처 스타일로, 자원을 정의하고 자원에 대한 작업을 HTTP 프로토콜을 통해 처리합니다.2000년, 로이 필딩(Roy Fielding)의 박사 학위 논문에서 소개되었습니다.1.2 REST API란?REST API는 REST 아키텍처 스타일을 따르는 응용 프로그램 인터페이스(API)입니다.웹에서 클라이언트-서버 간 데이터를 주고받기 위해 설계됩니다.2. REST의 핵심 원칙REST는 다음 6가지 아키텍처 제약을 따릅니다:2.1 클라이언트-서버 (Client-Server)클라이언트는 사용자 인터페이스(UI)를 담당하고, 서버는 데이터 저장 및 비즈니스 로직을 담당.두 컴포넌트는 ..
Spring Web MVC - 파일 다운로드
·
Spring
1 업로드 요청URL: /upload_form요청 방식: GET설명: 클라이언트가 업로드 양식을 요청하고, 서버는 HTML 폼을 렌더링합니다.upload_form.jsp클라이언트가 파일을 선택하고 서버로 업로드할 수 있는 HTML 폼.enctype="multipart/form-data" 설정으로 Multipart 요청을 지원.2 업로드 처리URL: /upload_ok요청 방식: POST설명: 클라이언트가 파일을 업로드하면, 서버는 파일을 지정된 경로에 저장하고 업로드된 파일의 목록을 보여줍니다.업로드 프로세스클라이언트가 업로드한 파일은 MultipartFile로 처리.파일명 고유화:원래 파일명에 System.nanoTime() 추가하여 이름 충돌 방지.저장 경로 설정:파일은 C:/java/upload2에..
Spring Web MVC - 파일 업로드와 MultipartFile
·
Spring
https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-servlet/multipart.html Multipart Resolver :: Spring FrameworkServlet multipart parsing needs to be enabled through Servlet container configuration. To do so: In Java, set a MultipartConfigElement on the Servlet registration. In web.xml, add a " " section to the servlet declaration. The following example shows how todocs.spring.io 1..
HttpServletRequest 객체에서 Parameter와 Attribute의 차이
·
Spring
Spring MVC 또는 Servlet 기반 웹 애플리케이션에서 HttpServletRequest 객체는 Parameter와 Attribute를 사용하여 데이터를 처리합니다. 두 개념은 역할과 사용 방법에서 차이가 있으므로 정확히 이해하는 것이 중요합니다.1. 개념1.1 Parameter클라이언트(브라우저)에서 전송된 요청 데이터를 의미.주로 폼 데이터(POST 요청) 또는 쿼리 스트링(GET 요청)으로 전달된 값.request.getParameter() 메서드를 사용하여 읽음.읽기 전용: 값을 변경하거나 추가할 수 없음.1.2 Attribute서버 내부에서 데이터를 공유하기 위해 저장하는 데이터.컨트롤러, 필터, 인터셉터 등에서 설정하여 이후 요청 흐름에서 사용.request.setAttribute()..
Spring Web MVC - WebMvcConfigurer
·
Spring
https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-config.html MVC Config :: Spring FrameworkThe MVC Java configuration and the MVC XML namespace provide default configuration suitable for most applications and a configuration API to customize it.docs.spring.io https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-config/customize.html#page-title MVC Config API :: Spring..
Spring Web MVC - HandlerInterceptor
·
Spring
https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-servlet/handlermapping-interceptor.html Interception :: Spring FrameworkAll HandlerMapping implementations support handler interception which is useful when you want to apply functionality across requests. A HandlerInterceptor can implement the following:docs.spring.io https://docs.spring.io/spring-framework/reference/web/webmvc/mv..
리다이렉트(Redirect)와 포워드(Forward)
·
Spring
https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-servlet/viewresolver.html#mvc-redirecting-redirect-prefix View Resolution :: Spring FrameworkYou can also use a special forward: prefix for view names that are ultimately resolved by UrlBasedViewResolver and subclasses. This creates an InternalResourceView, which does a RequestDispatcher.forward(). Therefore, this prefix is not use..
스프링 JWT 심화 9 : 로그아웃
·
Spring Security/JWT
로그아웃 기능로그아웃 기능을 통해 추가적인 JWT 탈취 시간을 줄일 수 있다.로그아웃 버튼 클릭 시프론트엔드 측 : 로컬 스토리지에 존재하는 Access 토큰 삭제 및 서버 측 로그아웃 경로로 Refresh 토큰 전송백엔드 측 : 로그아웃 로직을 추가하여 Refresh 토큰을 받아 쿠키 초기화 후 Refresh DB에서 해당 Refresh 토큰 삭제 (모든 계정에서 로그아웃 구현 시 username 기반으로 모든 Refresh 토큰 삭제)백엔드에서 로그아웃 수행 작업DB에 저장하고 있는 Refresh 토큰 삭제Refresh 토큰 쿠키 null로 변경스프링 시큐리티에서의 로그아웃 구현의 위치일반적으로 스프링 시큐리티 의존성을 프로젝트에 추가했을 경우 기본 로그아웃 기능이 활성화 된다. 해당 로그아웃을 수행..