[Spring][쇼핑몰 프로젝트][31] 검색 구현(조건 검색 적용 -1)

https://kimvampa.tistory.com/245
This commit is contained in:
SeoJin Kim
2021-08-26 17:13:07 +09:00
parent 1e99f55b4e
commit 04bb6405bc
12 changed files with 153 additions and 6 deletions

View File

@@ -13,4 +13,7 @@ public interface BookMapper {
/* 상품 총 갯수 */
public int goodsGetTotal(Criteria cri);
/* 작가 id 리스트 요청 */
public String[] getAuthorIdList(String keyword);
}

View File

@@ -1,5 +1,7 @@
package com.vam.model;
import java.util.Arrays;
public class Criteria {
/* 현재 페이지 번호 */
@@ -14,6 +16,12 @@ public class Criteria {
/* 검색 키워드 */
private String keyword;
/* 작가 리스트 */
private String[] authorArr;
/* 카테고리 코드 */
private String cateCode;
/* Criteria 생성자 */
public Criteria(int pageNum, int amount) {
this.pageNum = pageNum;
@@ -62,10 +70,28 @@ public class Criteria {
this.keyword = keyword;
}
public String[] getAuthorArr() {
return authorArr;
}
public void setAuthorArr(String[] authorArr) {
this.authorArr = authorArr;
}
public String getCateCode() {
return cateCode;
}
public void setCateCode(String cateCode) {
this.cateCode = cateCode;
}
@Override
public String toString() {
return "Criteria [pageNum=" + pageNum + ", amount=" + amount + ", type=" + type + ", keyword=" + keyword + "]";
return "Criteria [pageNum=" + pageNum + ", amount=" + amount + ", type=" + type + ", keyword=" + keyword
+ ", authorArr=" + Arrays.toString(authorArr) + ", cateCode=" + cateCode + "]";
}
}

View File

@@ -24,6 +24,16 @@ public class BookServiceImpl implements BookService{
log.info("getGoodsList().......");
String type = cri.getType();
String[] typeArr = type.split("");
for(String t : typeArr) {
if(t.equals("A")) {
String[] authorArr = bookMapper.getAuthorIdList(cri.getKeyword());
cri.setAuthorArr(authorArr);
}
}
return bookMapper.getGoodsList(cri);
}

View File

@@ -42,6 +42,14 @@
<include refid="criteria"></include>
bookId >0
</select>
<!-- 작가 id 리스트 요청 -->
<select id="getAuthorIdList" resultType="String">
select authorid from vam_author where authorName like '%' || #{keyword} || '%'
</select>
</mapper>

View File

@@ -18,6 +18,7 @@ public class BookMapperTests {
@Autowired
private BookMapper mapper;
/*
@Test
public void getGoodsListTest() {
@@ -34,5 +35,25 @@ public class BookMapperTests {
System.out.println("totla : " + goodsTotal);
}
*/
/* 작가 id 리스트 요청 */
@Test
public void getAuthorId() {
String keyword = "";
String[] list = mapper.getAuthorIdList(keyword);
System.out.println("결과 : " + list.toString());
for(String id : list) {
System.out.println("개별 결과 : " + id);
}
}
}

View File

@@ -42,6 +42,14 @@
<include refid="criteria"></include>
bookId >0
</select>
<!-- 작가 id 리스트 요청 -->
<select id="getAuthorIdList" resultType="String">
select authorid from vam_author where authorName like '%' || #{keyword} || '%'
</select>
</mapper>

View File

@@ -13,4 +13,7 @@ public interface BookMapper {
/* 상품 총 갯수 */
public int goodsGetTotal(Criteria cri);
/* 작가 id 리스트 요청 */
public String[] getAuthorIdList(String keyword);
}

View File

@@ -1,5 +1,7 @@
package com.vam.model;
import java.util.Arrays;
public class Criteria {
/* 현재 페이지 번호 */
@@ -17,6 +19,12 @@ public class Criteria {
/* 검색 키워드 */
private String keyword;
/* 작가 리스트 */
private String[] authorArr;
/* 카테고리 코드 */
private String cateCode;
/* Criteria 생성자 */
public Criteria(int pageNum, int amount) {
this.pageNum = pageNum;
@@ -76,10 +84,27 @@ public class Criteria {
this.keyword = keyword;
}
public String[] getAuthorArr() {
return authorArr;
}
public void setAuthorArr(String[] authorArr) {
this.authorArr = authorArr;
}
public String getCateCode() {
return cateCode;
}
public void setCateCode(String cateCode) {
this.cateCode = cateCode;
}
@Override
public String toString() {
return "Criteria [pageNum=" + pageNum + ", amount=" + amount + ", skip=" + skip + ", type=" + type
+ ", keyword=" + keyword + "]";
return "Criteria [pageNum=" + pageNum + ", amount=" + amount + ", type=" + type + ", keyword=" + keyword
+ ", authorArr=" + Arrays.toString(authorArr) + ", cateCode=" + cateCode + "]";
}

View File

@@ -24,6 +24,16 @@ public class BookServiceImpl implements BookService{
log.info("getGoodsList().......");
String type = cri.getType();
String[] typeArr = type.split("");
for(String t : typeArr) {
if(t.equals("A")) {
String[] authorArr = bookMapper.getAuthorIdList(cri.getKeyword());
cri.setAuthorArr(authorArr);
}
}
return bookMapper.getGoodsList(cri);
}

View File

@@ -30,6 +30,13 @@
<include refid="criteria"></include>
</select>
</select>
<!-- 작가 id 리스트 요청 -->
<select id="getAuthorIdList" resultType="String">
select authorid from vam_author where authorname like concat ('%', #{keyword}, '%')
</select>
</mapper>

View File

@@ -16,7 +16,7 @@ import com.vam.model.Criteria;
public class BookMapperTests {
@Autowired
private BookMapper mapper;
/*
@Test
public void getGoodsListTest() {
@@ -33,5 +33,24 @@ public class BookMapperTests {
System.out.println("totla : " + goodsTotal);
}
*/
/* 작가 id 리스트 요청 */
@Test
public void getAuthorId() {
String keyword = "";
String[] list = mapper.getAuthorIdList(keyword);
System.out.println("결과 : " + list.toString());
for(String id : list) {
System.out.println("개별 결과 : " + id);
}
}
}

View File

@@ -30,6 +30,13 @@
<include refid="criteria"></include>
</select>
</select>
<!-- 작가 id 리스트 요청 -->
<select id="getAuthorIdList" resultType="String">
select authorid from vam_author where authorname like concat ('%', #{keyword}, '%')
</select>
</mapper>