[Spring][쇼핑몰 프로젝트][31] 검색 구현(기본 기능 구현)
https://kimvampa.tistory.com/244
This commit is contained in:
@@ -13,13 +13,18 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.vam.mapper.AttachMapper;
|
||||
import com.vam.model.AttachImageVO;
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.PageDTO;
|
||||
import com.vam.service.AttachService;
|
||||
import com.vam.service.BookService;
|
||||
|
||||
@Controller
|
||||
public class BookController {
|
||||
@@ -27,7 +32,10 @@ public class BookController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BookController.class);
|
||||
|
||||
@Autowired
|
||||
private AttachMapper attachMapper;
|
||||
private AttachService attachService;
|
||||
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
|
||||
//메인 페이지 이동
|
||||
@RequestMapping(value="/main", method = RequestMethod.GET)
|
||||
@@ -69,10 +77,34 @@ public class BookController {
|
||||
|
||||
logger.info("getAttachList.........." + bookId);
|
||||
|
||||
return new ResponseEntity<List<AttachImageVO>>(attachMapper.getAttachList(bookId), HttpStatus.OK);
|
||||
return new ResponseEntity<List<AttachImageVO>>(attachService.getAttachList(bookId), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
/* 상품 검색 */
|
||||
@GetMapping("search")
|
||||
public String searchGoodsGET(Criteria cri, Model model) {
|
||||
|
||||
logger.info("cri : " + cri);
|
||||
|
||||
List<BookVO> list = bookService.getGoodsList(cri);
|
||||
logger.info("pre list : " + list);
|
||||
if(!list.isEmpty()) {
|
||||
model.addAttribute("list", list);
|
||||
logger.info("list : " + list);
|
||||
} else {
|
||||
model.addAttribute("listcheck", "empty");
|
||||
|
||||
return "search";
|
||||
}
|
||||
|
||||
model.addAttribute("pageMaker", new PageDTO(cri, bookService.goodsGetTotal(cri)));
|
||||
|
||||
|
||||
return "search";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
16
VamPa/src/main/java/com/vam/mapper/BookMapper.java
Normal file
16
VamPa/src/main/java/com/vam/mapper/BookMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.vam.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
public interface BookMapper {
|
||||
|
||||
/* 상품 검색 */
|
||||
public List<BookVO> getGoodsList(Criteria cri);
|
||||
|
||||
/* 상품 총 갯수 */
|
||||
public int goodsGetTotal(Criteria cri);
|
||||
|
||||
}
|
||||
16
VamPa/src/main/java/com/vam/service/BookService.java
Normal file
16
VamPa/src/main/java/com/vam/service/BookService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
public interface BookService {
|
||||
|
||||
/* 상품 검색 */
|
||||
public List<BookVO> getGoodsList(Criteria cri);
|
||||
|
||||
/* 상품 총 갯수 */
|
||||
public int goodsGetTotal(Criteria cri);
|
||||
|
||||
}
|
||||
40
VamPa/src/main/java/com/vam/service/BookServiceImpl.java
Normal file
40
VamPa/src/main/java/com/vam/service/BookServiceImpl.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.vam.mapper.BookMapper;
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
@Service
|
||||
@Log4j
|
||||
public class BookServiceImpl implements BookService{
|
||||
|
||||
@Autowired
|
||||
private BookMapper bookMapper;
|
||||
|
||||
/* 상품 검색 */
|
||||
@Override
|
||||
public List<BookVO> getGoodsList(Criteria cri) {
|
||||
|
||||
log.info("getGoodsList().......");
|
||||
|
||||
return bookMapper.getGoodsList(cri);
|
||||
}
|
||||
|
||||
/* 사품 총 갯수 */
|
||||
@Override
|
||||
public int goodsGetTotal(Criteria cri) {
|
||||
|
||||
log.info("goodsGetTotal().......");
|
||||
|
||||
return bookMapper.goodsGetTotal(cri);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
VamPa/src/main/resources/com/vam/mapper/BookMapper.xml
Normal file
47
VamPa/src/main/resources/com/vam/mapper/BookMapper.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.vam.mapper.BookMapper">
|
||||
|
||||
<!-- criteria(검색조건) -->
|
||||
<sql id="criteria">
|
||||
<if test="keyword != null">
|
||||
bookName like '%' || #{keyword} || '%' and
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
|
||||
<!-- 상품 검색 -->
|
||||
<select id="getGoodsList" resultType="com.vam.model.BookVO">
|
||||
|
||||
<![CDATA[
|
||||
select * from(
|
||||
select /*+INDEX_DESC(vam_book SYS_C008227)*/ rownum as rn, bookId, bookName,
|
||||
(select authorName from vam_author where vam_book.authorId = vam_author.authorId) authorName, authorId,
|
||||
(select cateName from vam_bcate where vam_book.cateCode = vam_bcate.cateCode) cateName,cateCode, publisher, publeYear, bookPrice
|
||||
from vam_book
|
||||
where
|
||||
]]>
|
||||
|
||||
<include refid="criteria"></include>
|
||||
|
||||
<![CDATA[
|
||||
rownum <= #{pageNum} * #{amount}
|
||||
)
|
||||
where rn > (#{pageNum} -1) * #{amount}
|
||||
]]>
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 상품 총 개수 -->
|
||||
<select id="goodsGetTotal" resultType="int">
|
||||
|
||||
select count(*) from vam_book
|
||||
where
|
||||
<include refid="criteria"></include>
|
||||
bookId >0
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -52,7 +52,14 @@
|
||||
<a href="/main"><img src="resources/img/mLogo.png"></a>
|
||||
</div>
|
||||
<div class="search_area">
|
||||
<h1>Search area</h1>
|
||||
<div class="search_wrap">
|
||||
<form id="searchForm" action="/search" method="get">
|
||||
<div class="search_input">
|
||||
<input type="text" name="keyword">
|
||||
<button class='btn search_btn'>검 색</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="login_area">
|
||||
|
||||
|
||||
18
VamPa/src/main/webapp/WEB-INF/views/search.jsp
Normal file
18
VamPa/src/main/webapp/WEB-INF/views/search.jsp
Normal file
@@ -0,0 +1,18 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>검색결과</h1>
|
||||
<div>
|
||||
${list}
|
||||
</div>
|
||||
<div>
|
||||
${pageMaker}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -56,7 +56,7 @@ a{
|
||||
.search_area{
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
background-color: yellow;
|
||||
|
||||
float:left;
|
||||
}
|
||||
/* 로그인 버튼 영역 */
|
||||
|
||||
38
VamPa/src/test/java/com/vam/mapper/BookMapperTests.java
Normal file
38
VamPa/src/test/java/com/vam/mapper/BookMapperTests.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.vam.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
public class BookMapperTests {
|
||||
|
||||
@Autowired
|
||||
private BookMapper mapper;
|
||||
|
||||
@Test
|
||||
public void getGoodsListTest() {
|
||||
|
||||
Criteria cri = new Criteria();
|
||||
// 테스트 키워드
|
||||
cri.setKeyword("test");
|
||||
System.out.println("cri : " + cri);
|
||||
|
||||
List<BookVO> list = mapper.getGoodsList(cri);
|
||||
System.out.println("list : " + list);
|
||||
|
||||
System.out.println("==========");
|
||||
int goodsTotal = mapper.goodsGetTotal(cri);
|
||||
System.out.println("totla : " + goodsTotal);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
VamPa/target/classes/com/vam/mapper/BookMapper.xml
Normal file
47
VamPa/target/classes/com/vam/mapper/BookMapper.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.vam.mapper.BookMapper">
|
||||
|
||||
<!-- criteria(검색조건) -->
|
||||
<sql id="criteria">
|
||||
<if test="keyword != null">
|
||||
bookName like '%' || #{keyword} || '%' and
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
|
||||
<!-- 상품 검색 -->
|
||||
<select id="getGoodsList" resultType="com.vam.model.BookVO">
|
||||
|
||||
<![CDATA[
|
||||
select * from(
|
||||
select /*+INDEX_DESC(vam_book SYS_C008227)*/ rownum as rn, bookId, bookName,
|
||||
(select authorName from vam_author where vam_book.authorId = vam_author.authorId) authorName, authorId,
|
||||
(select cateName from vam_bcate where vam_book.cateCode = vam_bcate.cateCode) cateName,cateCode, publisher, publeYear, bookPrice
|
||||
from vam_book
|
||||
where
|
||||
]]>
|
||||
|
||||
<include refid="criteria"></include>
|
||||
|
||||
<![CDATA[
|
||||
rownum <= #{pageNum} * #{amount}
|
||||
)
|
||||
where rn > (#{pageNum} -1) * #{amount}
|
||||
]]>
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 상품 총 개수 -->
|
||||
<select id="goodsGetTotal" resultType="int">
|
||||
|
||||
select count(*) from vam_book
|
||||
where
|
||||
<include refid="criteria"></include>
|
||||
bookId >0
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Wed Aug 11 10:43:19 KST 2021
|
||||
#Tue Aug 24 20:56:59 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
|
||||
m2e.projectName=VamPa
|
||||
groupId=com.vam
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -20,6 +21,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.vam.mapper.AttachMapper;
|
||||
import com.vam.model.AttachImageVO;
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
import com.vam.model.PageDTO;
|
||||
import com.vam.service.AttachService;
|
||||
import com.vam.service.BookService;
|
||||
|
||||
@Controller
|
||||
public class BookController {
|
||||
@@ -27,7 +33,10 @@ public class BookController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BookController.class);
|
||||
|
||||
@Autowired
|
||||
private AttachMapper attachMapper;
|
||||
private AttachService attachService;
|
||||
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
|
||||
//메인 페이지 이동
|
||||
@RequestMapping(value="/main", method = RequestMethod.GET)
|
||||
@@ -68,9 +77,33 @@ public class BookController {
|
||||
|
||||
logger.info("getAttachList.........." + bookId);
|
||||
|
||||
return new ResponseEntity<List<AttachImageVO>>(attachMapper.getAttachList(bookId), HttpStatus.OK);
|
||||
return new ResponseEntity<List<AttachImageVO>>(attachService.getAttachList(bookId), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
/* 상품 검색 */
|
||||
@GetMapping("search")
|
||||
public String searchGoodsGET(Criteria cri, Model model) {
|
||||
|
||||
logger.info("cri : " + cri);
|
||||
|
||||
List<BookVO> list = bookService.getGoodsList(cri);
|
||||
logger.info("pre list : " + list);
|
||||
if(!list.isEmpty()) {
|
||||
model.addAttribute("list", list);
|
||||
logger.info("list : " + list);
|
||||
} else {
|
||||
model.addAttribute("listcheck", "empty");
|
||||
|
||||
return "search";
|
||||
}
|
||||
|
||||
model.addAttribute("pageMaker", new PageDTO(cri, bookService.goodsGetTotal(cri)));
|
||||
|
||||
|
||||
return "search";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
16
VamPa_MySQL/src/main/java/com/vam/mapper/BookMapper.java
Normal file
16
VamPa_MySQL/src/main/java/com/vam/mapper/BookMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.vam.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
public interface BookMapper {
|
||||
|
||||
/* 상품 검색 */
|
||||
public List<BookVO> getGoodsList(Criteria cri);
|
||||
|
||||
/* 상품 총 갯수 */
|
||||
public int goodsGetTotal(Criteria cri);
|
||||
|
||||
}
|
||||
16
VamPa_MySQL/src/main/java/com/vam/service/BookService.java
Normal file
16
VamPa_MySQL/src/main/java/com/vam/service/BookService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
public interface BookService {
|
||||
|
||||
/* 상품 검색 */
|
||||
public List<BookVO> getGoodsList(Criteria cri);
|
||||
|
||||
/* 상품 총 갯수 */
|
||||
public int goodsGetTotal(Criteria cri);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.vam.mapper.BookMapper;
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
@Service
|
||||
@Log4j
|
||||
public class BookServiceImpl implements BookService{
|
||||
|
||||
@Autowired
|
||||
private BookMapper bookMapper;
|
||||
|
||||
/* 상품 검색 */
|
||||
@Override
|
||||
public List<BookVO> getGoodsList(Criteria cri) {
|
||||
|
||||
log.info("getGoodsList().......");
|
||||
|
||||
return bookMapper.getGoodsList(cri);
|
||||
}
|
||||
|
||||
/* 사품 총 갯수 */
|
||||
@Override
|
||||
public int goodsGetTotal(Criteria cri) {
|
||||
|
||||
log.info("goodsGetTotal().......");
|
||||
|
||||
return bookMapper.goodsGetTotal(cri);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
35
VamPa_MySQL/src/main/resources/com/vam/mapper/BookMapper.xml
Normal file
35
VamPa_MySQL/src/main/resources/com/vam/mapper/BookMapper.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.vam.mapper.BookMapper">
|
||||
|
||||
<!-- criteria(검색조건) -->
|
||||
<sql id="criteria">
|
||||
<if test="keyword != null">
|
||||
where (bookName like concat ('%', #{keyword}, '%'))
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!-- 상품 검색 -->
|
||||
<select id="getGoodsList" resultType="com.vam.model.BookVO">
|
||||
|
||||
select bookId, bookName, b.authorName, a.authorId, c.cateName, a.cateCode, publisher, publeYear, bookPrice
|
||||
from vam_book a left outer join vam_author b on a.authorId = b.authorId
|
||||
left outer join vam_bcate c on a.cateCode = c.cateCode
|
||||
<include refid="criteria"></include>
|
||||
order by bookId desc
|
||||
limit #{skip}, #{amount}
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 상품 총 개수 -->
|
||||
<select id="goodsGetTotal" resultType="int">
|
||||
|
||||
select count(*) from vam_book
|
||||
|
||||
<include refid="criteria"></include>
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -52,7 +52,14 @@
|
||||
<a href="/main"><img src="resources/img/mLogo.png"></a>
|
||||
</div>
|
||||
<div class="search_area">
|
||||
<h1>Search area</h1>
|
||||
<div class="search_wrap">
|
||||
<form id="searchForm" action="/search" method="get">
|
||||
<div class="search_input">
|
||||
<input type="text" name="keyword">
|
||||
<button class='btn search_btn'>검 색</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="login_area">
|
||||
|
||||
|
||||
18
VamPa_MySQL/src/main/webapp/WEB-INF/views/search.jsp
Normal file
18
VamPa_MySQL/src/main/webapp/WEB-INF/views/search.jsp
Normal file
@@ -0,0 +1,18 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>검색결과</h1>
|
||||
<div>
|
||||
${list}
|
||||
</div>
|
||||
<div>
|
||||
${pageMaker}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -56,7 +56,7 @@ a{
|
||||
.search_area{
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
background-color: yellow;
|
||||
|
||||
float:left;
|
||||
}
|
||||
/* 로그인 버튼 영역 */
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.vam.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
public class BookMapperTests {
|
||||
@Autowired
|
||||
private BookMapper mapper;
|
||||
|
||||
@Test
|
||||
public void getGoodsListTest() {
|
||||
|
||||
Criteria cri = new Criteria();
|
||||
// 테스트 키워드
|
||||
cri.setKeyword("test");
|
||||
System.out.println("cri : " + cri);
|
||||
|
||||
List<BookVO> list = mapper.getGoodsList(cri);
|
||||
System.out.println("list : " + list);
|
||||
|
||||
System.out.println("==========");
|
||||
int goodsTotal = mapper.goodsGetTotal(cri);
|
||||
System.out.println("totla : " + goodsTotal);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
35
VamPa_MySQL/target/classes/com/vam/mapper/BookMapper.xml
Normal file
35
VamPa_MySQL/target/classes/com/vam/mapper/BookMapper.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.vam.mapper.BookMapper">
|
||||
|
||||
<!-- criteria(검색조건) -->
|
||||
<sql id="criteria">
|
||||
<if test="keyword != null">
|
||||
where (bookName like concat ('%', #{keyword}, '%'))
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!-- 상품 검색 -->
|
||||
<select id="getGoodsList" resultType="com.vam.model.BookVO">
|
||||
|
||||
select bookId, bookName, b.authorName, a.authorId, c.cateName, a.cateCode, publisher, publeYear, bookPrice
|
||||
from vam_book a left outer join vam_author b on a.authorId = b.authorId
|
||||
left outer join vam_bcate c on a.cateCode = c.cateCode
|
||||
<include refid="criteria"></include>
|
||||
order by bookId desc
|
||||
limit #{skip}, #{amount}
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 상품 총 개수 -->
|
||||
<select id="goodsGetTotal" resultType="int">
|
||||
|
||||
select count(*) from vam_book
|
||||
|
||||
<include refid="criteria"></include>
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Wed Aug 11 10:43:21 KST 2021
|
||||
#Tue Aug 24 21:05:30 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
|
||||
m2e.projectName=VamPa_MySQL
|
||||
groupId=com.vam
|
||||
|
||||
Reference in New Issue
Block a user