persitence.xml
OrderApiController.java package com.kyhslam.api; import com.kyhslam.domain.Order; import com.kyhslam.domain.OrderItem; import com.kyhslam.repository.OrderRepository; import com.kyhslam.repository.OrderSearch; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequiredArgsConstructor public class OrderApiCo..
package com.kyhslam; import com.kyhslam.domain.*; import com.kyhslam.domain.item.Book; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; import javax.persistence.EntityManager; @Component @RequiredArgsConstructor public class InitDb { private final InitSer..
API 설계 시 주의점 API 파라미터 받을때나 보낼때는 절대로 엔티티를 사용하면 안된다. 항상 DTO를 만들어서 필요한 정보만 내보내도록 해야한다! 필수! import java.util.List; import java.util.stream.Collectors; @RestController @RequiredArgsConstructor public class MemberApiController { private final MemberService memberService; /** * 멤버 조회 * 문제점 : 엔티티 모든것이 노출 등 * @return */ @GetMapping("/api/v1/members") public List membersV1() { return memberService.findMem..
MemberApiController.java /** * 수정 API * @param id * @param request * @return */ @PutMapping("/api/v2/members/{id}") public UpdateMemberResponse updateMemberV2( @PathVariable("id") Long id, @RequestBody @Valid UpdateMemberRequest request){ memberService.update(id, request.getName()); Member findMember = memberService.findOne(id); return new UpdateMemberResponse(findMember.getId(), findMember.getN..
꼭 API스펙을 위한 별도의 DTO를 만들어 사용하는것이 제일 좋다. 실무에서는 API 만들때 엔티티를 직접 받지도 말고 보내지도 말라.(직접 노출X) MemberApiController.java package com.jpabook.api; import com.jpabook.domain.Member; import com.jpabook.service.MemberService; import lombok.Data; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import o..
orderList.html 주문상태 option 검색 # 회원명 대표상품 이름 대표상품 주문가격 대표상품 주문수량 상태 일시 CANCEL OrderRepository.java public List findAllByString(OrderSearch orderSearch) { //language = JPQL String jpql = "select o from Order o join o.member m"; boolean isFirstCondition = true; //주문상태 검색 if(orderSearch.getOrderStatus() != null) { if(isFirstCondition) { jpql += " where"; isFirstCondition = false; }else{ jpql += " an..
orderForm.html 주문회원 회원선택 상품명 상품선택 주문수량 Submit orderList.html 주문상태 option 검색 # 회원명 대표상품 이름 대표상품 주문가격 대표상품 주문수량 상태 일시 CANCEL df OrderController.java package com.jpabook.controller; import com.jpabook.domain.Member; import com.jpabook.domain.item.Item; import com.jpabook.service.ItemService; import com.jpabook.service.MemberService; import com.jpabook.service.OrderService; import lombok.RequiredArg..
ItemController.java /** * ITEM 수정을 위한 상세화면 * @param itemId * @param model * @return */ @GetMapping("items/{itemId}/edit") public String updateItemForm(@PathVariable("itemId") Long itemId, Model model) { Book item = (Book) itemService.findOne(itemId); BookForm form = new BookForm(); form.setId(item.getId()); form.setName(item.getName()); form.setPrice(item.getPrice()); form.setStockQuantity(item...
먼저 DTO를 생성한다. BookForm package com.kyhslam.controller; import lombok.Getter; import lombok.Setter; @Setter @Getter public class BookForm { private Long id; private String name; private int price; private int stockQuantity; private String author; private String isbn; } ItemController package com.kyhslam.controller; import com.kyhslam.domain.item.Book; import com.kyhslam.domain.item.Item; import c..
MemberForm package com.kyhslam.controller; import lombok.Getter; import lombok.Setter; import javax.validation.constraints.NotEmpty; @Setter @Getter public class MemberForm { @NotEmpty(message = "회원 이름은 필수입니다.") private String name; private String city; private String street; private String zipcode; } MemberController package com.kyhslam.controller; import com.kyhslam.domain.Address; import com...
thymeleaf 사이트 : www.thymeleaf.org/ Thymeleaf Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati www.thymeleaf.org thymeleaf 튜토리얼 : www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html Tuto..