Spring Boot (Maven)/2차 미니프로젝트

상품등록, 상품 찜 했을때 로그인한 userid를 DB에 저장

pjh8838 2024. 6. 20. 15:40
반응형

1. 상품 찜 했을때 로그인한 id값이 cart DB에 저장

컨트롤러, BindingResult 는 @Valid 쓸때 쓰는건데 검증오류를 저장하는 객체임

 

로그인한 유저 id값 받는 스프링부트 시큐리티 로직

Authentication auth = SecurityContextHolder.getContext().getAuthentication();

UserDTO xxx = (UserDTO)auth.getPrincipal();

dto.setUserid(xxx.getUserid());

매퍼

 

매퍼.java
서비스

 


2. 상품 찜하고 cart DB에 로그인한 id 저장 후 장바구니 페이지에서 로그인한 id와 일치하는 리스트만 불러오기

 

컨트롤러

 

ModelMap 쓸때 - 위에 처럼 적용

 

Authentication auth = SecurityContextHolder.getContext().getAuthentication();

UserDTO xxx = (UserDTO)auth.getPrincipal();

dto.setUserid(xxx.getUserid());

 

매퍼
매퍼.java
서비스

 

728x90
반응형