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

https://kimvampa.tistory.com/246
This commit is contained in:
SeoJin Kim
2021-08-31 18:56:51 +09:00
parent 04bb6405bc
commit 4a8fc4070c
4 changed files with 100 additions and 12 deletions

View File

@@ -6,9 +6,31 @@
<!-- criteria(검색조건) -->
<sql id="criteria">
<if test="keyword != null">
bookName like '%' || #{keyword} || '%' and
</if>
<trim prefix="(" suffix=") AND" prefixOverrides="AND">
<foreach item="type" collection="typeArr">
<trim prefix="AND">
<choose>
<when test="type == 'A'.toString()">
<trim prefixOverrides="or">
<foreach collection="authorArr" item="authorId">
<trim prefix="or">
authorId = #{authorId}
</trim>
</foreach>
</trim>
</when>
<when test="type == 'C'.toString()">
cateCode like '%' || #{cateCode} || '%'
</when>
<when test="type == 'T'.toString()">
bookName like '%' || #{keyword} || '%'
</when>
</choose>
</trim>
</foreach>
</trim>
</sql>

View File

@@ -6,9 +6,31 @@
<!-- criteria(검색조건) -->
<sql id="criteria">
<if test="keyword != null">
bookName like '%' || #{keyword} || '%' and
</if>
<trim prefix="(" suffix=") AND" prefixOverrides="AND">
<foreach item="type" collection="typeArr">
<trim prefix="AND">
<choose>
<when test="type == 'A'.toString()">
<trim prefixOverrides="or">
<foreach collection="authorArr" item="authorId">
<trim prefix="or">
authorId = #{authorId}
</trim>
</foreach>
</trim>
</when>
<when test="type == 'C'.toString()">
cateCode like '%' || #{cateCode} || '%'
</when>
<when test="type == 'T'.toString()">
bookName like '%' || #{keyword} || '%'
</when>
</choose>
</trim>
</foreach>
</trim>
</sql>

View File

@@ -6,9 +6,31 @@
<!-- criteria(검색조건) -->
<sql id="criteria">
<if test="keyword != null">
where (bookName like concat ('%', #{keyword}, '%'))
</if>
<trim prefix="where (" suffix=")" prefixOverrides="AND">
<foreach item="type" collection="typeArr">
<trim prefix="AND">
<choose>
<when test="type == 'A'.toString()">
<trim prefixOverrides="or">
<foreach collection="authorArr" item="authorId">
<trim prefix="or">
a.authorId = #{authorId}
</trim>
</foreach>
</trim>
</when>
<when test="type == 'C'.toString()">
a.cateCode like concat ('%', #{cateCode}, '%')
</when>
<when test="type == 'T'.toString()">
bookName like concat ('%', #{keyword}, '%')
</when>
</choose>
</trim>
</foreach>
</trim>
</sql>
<!-- 상품 검색 -->

View File

@@ -6,9 +6,31 @@
<!-- criteria(검색조건) -->
<sql id="criteria">
<if test="keyword != null">
where (bookName like concat ('%', #{keyword}, '%'))
</if>
<trim prefix="where (" suffix=")" prefixOverrides="AND">
<foreach item="type" collection="typeArr">
<trim prefix="AND">
<choose>
<when test="type == 'A'.toString()">
<trim prefixOverrides="or">
<foreach collection="authorArr" item="authorId">
<trim prefix="or">
a.authorId = #{authorId}
</trim>
</foreach>
</trim>
</when>
<when test="type == 'C'.toString()">
a.cateCode like concat ('%', #{cateCode}, '%')
</when>
<when test="type == 'T'.toString()">
bookName like concat ('%', #{keyword}, '%')
</when>
</choose>
</trim>
</foreach>
</trim>
</sql>
<!-- 상품 검색 -->