동일 카테고리의 제품 추천

기여·2024년 8월 21일

소소한 개발팁

목록 보기
81/104

기획의도:

  • 제품 상세페이지 진입 시 해당 제품과 동일한 카테고리의 제품도 하단에서 표시
  • 해당 제품은 이미 보고 있으니 리스트에서 제외
  • 비슷한 제품이 많을 수 있으니 3개로 제한

Mapper

//동일 category의 제품 추천받기. 상세보는 건 제외
		@Select("SELECT * FROM products "
				+ "WHERE category = #{category} "
				+ "AND product_code != #{product_code} "
				+ "ORDER BY product_code DESC "
				+ "limit 3")	
		List<PrdVo> rcmPrdList(@Param("category") String category, 
				@Param("product_code") String product_code);

Ctrl

@GetMapping("viewPrd") //상품 상세보기
	public String viewPrd(Model model, PrdVo vo, ReviewVo rvo) {
		...
        "revListSize", reviewList.size()); // 후기 건수
	    
	    // 동일 category의 제품 추천받기. 상세보는 건 제외
	    List<PrdVo> rcmList = prdSvc.rcmPrdList(product.getCategory(), product.getProduct_code());
	    model.addAttribute("rcmList", rcmList);	    
	    
		return "prd/viewPrd";
	}

Front

<!-- 추천 -->
<div style="width: 800px; display: flex; flex-wrap: wrap; justify-content: center;">
<div class="separator-horizontal"></div> <!------------------------- 수평선 -------------------------->

  <div style="width: 100%;">
  <div th:if="${session.username != null and session.loginType == 'user'}">
      <span th:text="${session.username} + '님,'"></span>
  </div>
  <h3 style="margin-top: 0px;">이런 제품이 어떨까요?</h3>
  </div>

<!-- 반목문 -->
    
</div> <!-- allPrdCtn 끝 -->
<!-- 추천 끝 -->
profile
기기 좋아하는 여자

0개의 댓글