본문 바로가기
728x90
반응형

스프링187

[Spring] 상품 상세 BasicItemController에 추가 @GetMapping("/{itemId}") public String item(@PathVariable long itemId, Model model) { Item item = itemRepository.findById(itemId); model.addAttribute("item", item); return "basic/item"; } PathVariable 로 넘어온 상품ID로 상품을 조회하고, 모델에 담아둔다. 그리고 뷰 템플릿을 호출한다 상품 상세 뷰 정적 HTML을 뷰 템플릿(templates) 영역으로 복사하고 다음과 같이 수정 /resources/static/item.html → 복사 → /resources/templates/basic/item.html.. 2023. 6. 14.
[Spring] 상품 목록 - 타임리프(Thymeleaf) BasicItemController package hello.itemservice.web.basic; import hello.itemservice.domain.item.Item; import hello.itemservice.domain.item.ItemRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMappin.. 2023. 6. 14.
[Spring] 스프링 MVC - 상품 도메인 개발 및 상품 서비스 HTML - 부트스트랩 Item - 상품 객체 package hello.domain.item; import lombok.Data; @Data public class Item { private Long id; private String itemName; private Integer price; private Integer quantity; public Item() { } public Item(String itemName, Integer price, Integer quantity) { this.itemName = itemName; this.price = price; this.quantity = quantity; } } ItemRepository - 상품 저장소 package hello.domain.item; import org.s.. 2023. 6. 14.
[Spring] 스프링 MVC - 웹 페이지 만들기 프로젝트 생성, 요구사항 분 프로젝트 생성 GENERATE 로 다운로드 원하는 폴더에 압축을 푼다. intelliJ 에서 컴파일 실행 시 속도가 조금 느릴 수 있는데 그 현상을 개선하기 위해서는 File > Settings > Build, Execution, Deployment > Build Tools > Gradle 에서 Build and run using : IntelliJ IDEA Run tests using : IntelliJ IDEA 를 사용할 것 그러면 빌드 속도가 더 빨라질 것이다. 롬복 기능을 활성화 하기 위해서 Enable annotation processing 체크 build.gradle plugins { id 'java' id 'org.springframework.boot' version '2.7.12' id '.. 2023. 6. 13.
[Spring] 요청 매핑 핸들러 어뎁터 구조 그렇다면 HTTP 메시지 컨버터는 스프링 MVC 어디쯤에서 사용되는 것일까? SpringMVC 구조 핵심은 애노테이션 기반의 컨트롤러, 그러니까 @RequestMapping 을 처리하는 핸들러 어댑터인 RequestMappingHandlerAdapter(요청 매핑 핸들러 어뎁터)에 있다. RequestMappingHandlerAdapter 동작 방식 ArgumentResolver 생각해보면, 애노테이션 기반의 컨트롤러는 매우 다양한 파라미터를 사용할 수 있었다. HttpServletRequest, Model은 물론이고, @RequestParam, @ModelAttribute 같은 애노테이션 그리고 @RequestBody, HttpEntity 같은 HTTP 메시지를 처리하는 부분까지 큰 유연함을 보여주었다.. 2023. 6. 13.
[Spring] HTTP 메시지 컨버터 뷰 템플릿으로 HTML을 생성해서 응답하는 것이 아니라, HTTP API처럼 JSON 데이터를 HTTP 메시지 바디에서 직접 읽거나 쓰는 경우 HTTP 메시지 컨버터를 사용하면 편리하다. @ResponseBody 사용 원리 @ResponseBody를 사용 - HTTP의 body에 문자 내용을 직접 반환 - viewResolver 대신에 HttpMessageConverter가 동작 - 기본 문자 처리 : StringHttpMessageConverter - 기본 객체 처리 : MappingJAckson2HttpMessageConverter - byte 처리 등등 기타 여러 HttpMessageConverter 가 기본으로 등록되어 있음 ※ 참고 응답의 경우 클라이언트의 HTTP Accept 헤더와 서버의 컨.. 2023. 6. 13.
728x90
반응형