[Spring][쇼핑몰 프로젝트][52] 메인페이지 평점 순 상품 노출(서버처리)
https://kimvampa.tistory.com/303
This commit is contained in:
@@ -50,7 +50,8 @@ public class BookController {
|
||||
logger.info("메인 페이지 진입");
|
||||
|
||||
model.addAttribute("cate1", bookService.getCateCode1());
|
||||
model.addAttribute("cate2", bookService.getCateCode2());
|
||||
model.addAttribute("cate2", bookService.getCateCode2());
|
||||
model.addAttribute("ls", bookService.likeSelect());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.vam.model.BookVO;
|
||||
import com.vam.model.CateFilterDTO;
|
||||
import com.vam.model.CateVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.SelectDTO;
|
||||
|
||||
public interface BookMapper {
|
||||
|
||||
@@ -36,4 +37,7 @@ public interface BookMapper {
|
||||
/* 상품 id 이름 */
|
||||
public BookVO getBookIdName(int bookId);
|
||||
|
||||
/* 평줌순 상품 정보 */
|
||||
public List<SelectDTO> likeSelect();
|
||||
|
||||
}
|
||||
|
||||
69
VamPa/src/main/java/com/vam/model/SelectDTO.java
Normal file
69
VamPa/src/main/java/com/vam/model/SelectDTO.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.vam.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectDTO {
|
||||
|
||||
/* 상품 id */
|
||||
private int bookId;
|
||||
|
||||
/* 상품 이름 */
|
||||
private String bookName;
|
||||
|
||||
/* 카테고리 이름 */
|
||||
private String cateName;
|
||||
|
||||
private double ratingAvg;
|
||||
|
||||
/* 상품 이미지 */
|
||||
private List<AttachImageVO> imageList;
|
||||
|
||||
public int getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
|
||||
public void setBookId(int bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
public String getBookName() {
|
||||
return bookName;
|
||||
}
|
||||
|
||||
public void setBookName(String bookName) {
|
||||
this.bookName = bookName;
|
||||
}
|
||||
|
||||
public String getCateName() {
|
||||
return cateName;
|
||||
}
|
||||
|
||||
public void setCateName(String cateName) {
|
||||
this.cateName = cateName;
|
||||
}
|
||||
|
||||
public double getRatingAvg() {
|
||||
return ratingAvg;
|
||||
}
|
||||
|
||||
public void setRatingAvg(double ratingAvg) {
|
||||
this.ratingAvg = ratingAvg;
|
||||
}
|
||||
|
||||
public List<AttachImageVO> getImageList() {
|
||||
return imageList;
|
||||
}
|
||||
|
||||
public void setImageList(List<AttachImageVO> imageList) {
|
||||
this.imageList = imageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SelectDTO [bookId=" + bookId + ", bookName=" + bookName + ", cateName=" + cateName + ", ratingAvg="
|
||||
+ ratingAvg + ", imageList=" + imageList + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.vam.model.BookVO;
|
||||
import com.vam.model.CateFilterDTO;
|
||||
import com.vam.model.CateVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.SelectDTO;
|
||||
|
||||
public interface BookService {
|
||||
|
||||
@@ -28,6 +29,9 @@ public interface BookService {
|
||||
public BookVO getGoodsInfo(int bookId);
|
||||
|
||||
/* 상품 id 이름 */
|
||||
public BookVO getBookIdName(int bookId);
|
||||
public BookVO getBookIdName(int bookId);
|
||||
|
||||
/* 평줌순 상품 정보 */
|
||||
public List<SelectDTO> likeSelect();
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.vam.model.BookVO;
|
||||
import com.vam.model.CateFilterDTO;
|
||||
import com.vam.model.CateVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.SelectDTO;
|
||||
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
@@ -147,6 +148,26 @@ public class BookServiceImpl implements BookService{
|
||||
public BookVO getBookIdName(int bookId) {
|
||||
|
||||
return bookMapper.getBookIdName(bookId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SelectDTO> likeSelect() {
|
||||
|
||||
List<SelectDTO> list = bookMapper.likeSelect();
|
||||
|
||||
list.forEach(dto -> {
|
||||
|
||||
int bookId = dto.getBookId();
|
||||
|
||||
List<AttachImageVO> imageList = attachMapper.getAttachList(bookId);
|
||||
|
||||
dto.setImageList(imageList);
|
||||
|
||||
});
|
||||
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -174,6 +174,18 @@
|
||||
|
||||
</select>
|
||||
|
||||
<select id="likeSelect" resultType="com.vam.model.SelectDTO">
|
||||
|
||||
select * from
|
||||
(select rownum as rn, bookId, bookName, ratingAvg, (select cateName from vam_bcate where vam_book.cateCode = vam_bcate.cateCode) as cateName
|
||||
from vam_book
|
||||
order by ratingAvg desc nulls last)
|
||||
<![CDATA[
|
||||
where rn < 9
|
||||
]]>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -10,6 +10,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.SelectDTO;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
@@ -244,6 +245,7 @@ public class BookMapperTests {
|
||||
*/
|
||||
|
||||
/* 상품 정보 */
|
||||
/*
|
||||
@Test
|
||||
public void getGoodsInfo() {
|
||||
int bookId = 26;
|
||||
@@ -252,6 +254,17 @@ public class BookMapperTests {
|
||||
System.out.println(goodsInfo);
|
||||
System.out.println("===========================");
|
||||
|
||||
}*/
|
||||
|
||||
@Test
|
||||
public void likeSelectTest() {
|
||||
|
||||
|
||||
List<SelectDTO> likeSelect = mapper.likeSelect();
|
||||
for(SelectDTO dto : likeSelect) {
|
||||
System.out.println(dto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -174,6 +174,18 @@
|
||||
|
||||
</select>
|
||||
|
||||
<select id="likeSelect" resultType="com.vam.model.SelectDTO">
|
||||
|
||||
select * from
|
||||
(select rownum as rn, bookId, bookName, ratingAvg, (select cateName from vam_bcate where vam_book.cateCode = vam_bcate.cateCode) as cateName
|
||||
from vam_book
|
||||
order by ratingAvg desc nulls last)
|
||||
<![CDATA[
|
||||
where rn < 9
|
||||
]]>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Thu Feb 03 02:45:21 KST 2022
|
||||
#Mon Feb 07 20:50:26 KST 2022
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
|
||||
m2e.projectName=VamPa
|
||||
groupId=com.vam
|
||||
|
||||
@@ -50,7 +50,8 @@ public class BookController {
|
||||
logger.info("메인 페이지 진입");
|
||||
|
||||
model.addAttribute("cate1", bookService.getCateCode1());
|
||||
model.addAttribute("cate2", bookService.getCateCode2());
|
||||
model.addAttribute("cate2", bookService.getCateCode2());
|
||||
model.addAttribute("ls", bookService.likeSelect());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.vam.model.BookVO;
|
||||
import com.vam.model.CateFilterDTO;
|
||||
import com.vam.model.CateVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.SelectDTO;
|
||||
|
||||
public interface BookMapper {
|
||||
|
||||
@@ -36,4 +37,8 @@ public interface BookMapper {
|
||||
/* 상품 id 이름 */
|
||||
public BookVO getBookIdName(int bookId);
|
||||
|
||||
/* 평줌순 상품 정보 */
|
||||
public List<SelectDTO> likeSelect();
|
||||
|
||||
|
||||
}
|
||||
|
||||
67
VamPa_MySQL/src/main/java/com/vam/model/SelectDTO.java
Normal file
67
VamPa_MySQL/src/main/java/com/vam/model/SelectDTO.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.vam.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectDTO {
|
||||
|
||||
/* 상품 id */
|
||||
private int bookId;
|
||||
|
||||
/* 상품 이름 */
|
||||
private String bookName;
|
||||
|
||||
/* 카테고리 이름 */
|
||||
private String cateName;
|
||||
|
||||
private double ratingAvg;
|
||||
|
||||
/* 상품 이미지 */
|
||||
private List<AttachImageVO> imageList;
|
||||
|
||||
public int getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
|
||||
public void setBookId(int bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
public String getBookName() {
|
||||
return bookName;
|
||||
}
|
||||
|
||||
public void setBookName(String bookName) {
|
||||
this.bookName = bookName;
|
||||
}
|
||||
|
||||
public String getCateName() {
|
||||
return cateName;
|
||||
}
|
||||
|
||||
public void setCateName(String cateName) {
|
||||
this.cateName = cateName;
|
||||
}
|
||||
|
||||
public double getRatingAvg() {
|
||||
return ratingAvg;
|
||||
}
|
||||
|
||||
public void setRatingAvg(double ratingAvg) {
|
||||
this.ratingAvg = ratingAvg;
|
||||
}
|
||||
|
||||
public List<AttachImageVO> getImageList() {
|
||||
return imageList;
|
||||
}
|
||||
|
||||
public void setImageList(List<AttachImageVO> imageList) {
|
||||
this.imageList = imageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SelectDTO [bookId=" + bookId + ", bookName=" + bookName + ", cateName=" + cateName + ", ratingAvg="
|
||||
+ ratingAvg + ", imageList=" + imageList + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.vam.model.BookVO;
|
||||
import com.vam.model.CateFilterDTO;
|
||||
import com.vam.model.CateVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.SelectDTO;
|
||||
|
||||
public interface BookService {
|
||||
|
||||
@@ -28,6 +29,9 @@ public interface BookService {
|
||||
public BookVO getGoodsInfo(int bookId);
|
||||
|
||||
/* 상품 id 이름 */
|
||||
public BookVO getBookIdName(int bookId);
|
||||
public BookVO getBookIdName(int bookId);
|
||||
|
||||
/* 평줌순 상품 정보 */
|
||||
public List<SelectDTO> likeSelect();
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.vam.model.BookVO;
|
||||
import com.vam.model.CateFilterDTO;
|
||||
import com.vam.model.CateVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.SelectDTO;
|
||||
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
@@ -145,6 +146,26 @@ public class BookServiceImpl implements BookService{
|
||||
public BookVO getBookIdName(int bookId) {
|
||||
|
||||
return bookMapper.getBookIdName(bookId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SelectDTO> likeSelect() {
|
||||
|
||||
List<SelectDTO> list = bookMapper.likeSelect();
|
||||
|
||||
list.forEach(dto -> {
|
||||
|
||||
int bookId = dto.getBookId();
|
||||
|
||||
List<AttachImageVO> imageList = attachMapper.getAttachList(bookId);
|
||||
|
||||
dto.setImageList(imageList);
|
||||
|
||||
});
|
||||
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -158,6 +158,15 @@
|
||||
where bookId = #{bookId}
|
||||
|
||||
|
||||
</select>
|
||||
</select>
|
||||
|
||||
<select id="likeSelect" resultType="com.vam.model.SelectDTO">
|
||||
|
||||
select bookId, bookName, ratingAvg, (select cateName from vam_bcate where vam_book.cateCode = vam_bcate.cateCode) as cateName
|
||||
from vam_book
|
||||
order by ratingAvg desc limit 8
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -158,6 +158,15 @@
|
||||
where bookId = #{bookId}
|
||||
|
||||
|
||||
</select>
|
||||
</select>
|
||||
|
||||
<select id="likeSelect" resultType="com.vam.model.SelectDTO">
|
||||
|
||||
select bookId, bookName, ratingAvg, (select cateName from vam_bcate where vam_book.cateCode = vam_bcate.cateCode) as cateName
|
||||
from vam_book
|
||||
order by ratingAvg desc limit 8
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Thu Feb 03 02:45:21 KST 2022
|
||||
#Mon Feb 07 20:50:27 KST 2022
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
|
||||
m2e.projectName=VamPa_MySQL
|
||||
groupId=com.vam
|
||||
|
||||
Reference in New Issue
Block a user