스프링 3

Thymeleaf란? 그리고 기본적인 사용법

Thymeleaf 설정 https://start.spring.io/ 스프링 프로젝트를 생성할 때, 우측 dependency에서 thymeleaf를 추가해준다. 프로젝트에서 직접 추가를 하는 경우, 라이브러리를 추가 Gradle build.gradle implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' Maven pom.xml org.springframework.boot spring-boot-starter-thymeleaf 설정을 마쳤으면, thymeleaf를 사용할 html 파일 html 태그에 다음을 추가한다. Thymeleaf 기본 사용법 URL 링크 표현식 - @{...} 링크 - '/basic/link' 을 연결해준다. ..

ThymeLeaf 2023.05.29

@RequestBody, @ResponseBody - HTTP Message Body 조회, 반환

요청 파라미터(HTML Form으로 전송 및 쿼리스트링) 은 @RequestParam, @ModelAttribute를 사용해서 데이터를 조회하지만 HTTP 메시지 바디에 있는 데이터는 해당 어노테이션들로는 조회가 불가능하다. HTTP 메시지 바디를 조회할 수 있는 가장 기본적인 방법은 InputStream과 OutputStream을 사용하는 것이다. @PostMapping("/request-body-string-stream") public void requestBodyStringStream(InputStream inputStream, Writer responseWriter) throws IOException { String messageBody = StreamUtils.copyToString(inputS..

SPRING 2023.05.21

@RequestMapping - 요청 매핑

@RequsetMapping(value = "/hello-request") 은 value에 해당하는 값인 ex) /hello-request이라는 URL 요청이 오면 해당 어노테이션이 붙은 메서드를 실행하도록 매핑한다. @RequestMapping(value = "/hello-request") public String helloRequest() { return "ok"; } 즉, /hello-request로 URL 요청을 하면 helloRequest 메서드가 실행이 된다. method 속성 @RequestMapping(value = "/hello-request", method = RequestMethod.Get) URL 요청 방식이 method에 해당하는 요청 방식과 같아야 매핑을 해주는 역할을 한다. @..

SPRING 2023.05.14