
찜 목록 다이어그램.drawio
WishListController
// 찜 목록
@RequestMapping(value = "/wishList.do", method = {RequestMethod.GET,RequestMethod.POST})
public ModelAndView wishList(HttpServletRequest requ, HttpServletResponse resp,
@RequestParam Map<String, Object> map,
HttpSession session) throws Exception {
// 세션에서 아이디 가져오기
MemberDomain memberDomain = (MemberDomain) session.getAttribute("member");
String memberId = memberDomain.getMemberId();
// 찜 숫자를 세션에 담기
int wishListTotal = wishListService.allwishListCount(memberId);
session.setAttribute("wishListTotal", wishListTotal);
map.put("memberId", memberId);
Map<String, Object> productMap = wishListService.wishList(map);
ModelAndView mav = new ModelAndView("/mypage/wishlist/wishList");
System.out.println("상품 목록아 들어왔니? " + productMap);
mav.addObject("productMap", productMap);
return mav;
}
WishListServiceImpl
// 찜 목록
@Override
public Map<String, Object> wishList(Map<String, Object> map) throws Exception {
if(map.get("section") == null) {
map.put("section", 1);
map.put("pageNum", 1);
}
// 찜 수 가져옴.
String memberId = (String) map.get("memberId");
int recNum = allwishListCount(memberId);
// 가져온 상품 총 개수(중복제외) 20을 나누고 Math의 ceil로 소수점을 올림처리 = 페이지 수
// 여기서 20d는 한 페이지에 몇개의 상품을 표시할 것 인지
int pageNO = (int)Math.ceil(recNum/9d);
// 페에지 수에서 10을 나누고 Math의 ceil로 소수점을 올림처리 = 섹션
// 여기서 20d는 한 섹션에 페이지 수를 몇개 표시할 건지
int lastSection = (int)Math.ceil(pageNO/10d);
if(pageNO != 1) {
map.put("recNum", recNum);
map.put("pageNO", pageNO);
map.put("lastSection", lastSection);
}
List<ProductDomain> list = wishListDAO.wishList(map);
map.put("list", list);
return map;
}
@Override
public int allwishListCount(String memberId) throws Exception {
return wishListDAO.allwishListCount(memberId);
}
WishListDAOImpl
// 좋아요 총 글 수
@Override
public int allwishListCount(String memberId) throws DataAccessException {
return sqlSession.selectOne("mapper.wishList.allwishListCount", memberId);
}
// 좋아요 리스트
@Override
public List<ProductDomain> wishList(Map<String, Object> map) throws DataAccessException {
return sqlSession.selectList("mapper.wishList.wishList", map);
}
WishList.xml
<select id="allwishListCount" resultType="int" parameterType="String">
<![CDATA[
SELECT count(productName)
FROM wishlist
WHERE memberId = #{memberId}
]]>
</select>
<!-- 상품목록 + 저장된 image파일명(1개씩만) -->
<select id="wishList" resultType="productDomain" parameterType="java.util.Map">
<![CDATA[
SELECT recNum, productNO, productCategory, productName, productdescription, productPrice, productQty,
productUpdated, productoptions,imageFileName
FROM ((SELECT ROWNUM AS recNum, i.*, p.*
FROM (SELECT articleNO, imageFileName, ROW_NUMBER() OVER (PARTITION BY articleNO ORDER BY articleNO ASC) AS rn
FROM image) i , (SELECT productNO, productCategory, productName, productdescription, productPrice, productQty,
productUpdated, productoptions, ROW_NUMBER() OVER (PARTITION BY productName ORDER BY productNO) AS rn
FROM product
WHERE productName IN(
SELECT productName
FROM wishlist
WHERE memberId = #{memberId}
)
]]>
<if test="all == all">
<if test="category != null">
<![CDATA[WHERE productCategory = #{category}]]>
</if>
</if>
<![CDATA[ORDER BY productNO ASC) p
WHERE i.articleNO = p.productNO
AND i.RN = 1 AND p.RN = 1))
WHERE recNum between(#{section}-1)+(#{pageNum}-1)*9+1 and (#{section}-1)+#{pageNum}*9
]]>
</select>
WishList.jsp(페이징)
<div>
<p class="paging" align="center">
<c:choose>
<c:when test="${recNum != null }">
<c:forEach var="page" begin="1" end="${pageNo }" step="1" varStatus="a">
<c:if test="${section > 1 && page==1}">
<a href="${contextPath}/mypage/wishlist/wishList.do?section=${1 }&pageNum=${1 }">처음</a>
</c:if>
<c:if test="${section > 1 && page==1}">
<a href="${contextPath}/mypage/wishlist/wishList.do?section=${section-1}&pageNum=${(section-1)*10+page-1}">이전</a>
</c:if>
<c:if test="${page <= 10}">
<c:if test="${loopOut }" >
<a class="pageNum" href="${contextPath}/mypage/wishlist/wishList.do?section=${section}&pageNum=${(section-1)*10+page}">${(section-1)*10 +page}</a>
</c:if>
<c:if test="${((section-1)*10+page)==pageNo }">
<c:set var="loopOut" value="false" />
</c:if>
</c:if>
<c:if test="${page == 10}">
<c:if test="${loopOut }">
<a href="${contextPath}/mypage/wishlist/wishList.do?section=${section+1}&pageNum=${(section-1)*10+page+1}">다음</a>
</c:if>
</c:if>
</c:forEach>
<c:if test="${section < lastSection}">
<a href="${contextPath}/mypage/wishlist/wishList.do?section=${lastSection}&pageNum=${pageNo}">마지막</a>
</c:if>
</c:when>
<c:otherwise>
<a class="pageNum" href="${contextPath}/mypage/wishlist/wishList.do?section=${1}&pageNum=${1}">${1}</a>
</c:otherwise>
</c:choose>
</p>
</div>