내가 보려고 정리하는/Spring

검색 조건 설정하는 쿼리문 searchFrag

보동이용용 2023. 4. 13. 09:06
반응형

▶board.xml

detailCondition 검색 조건

<sql id="searchFrag">
    <trim prefix="WHERE" prefixOverrides="AND">
        <if test="detailCondition neq null">
            <if test="@org.apache.commons.lang3.StringUtils@isNotBlank(detailCondition.buyerLgu)">
                AND BUYER_LGU = #{detailCondition.buyerLgu}
            </if>
            <if test="@org.apache.commons.lang3.StringUtils@isNotBlank(detailCondition.buyerAdd1)">
                AND INSTR(BUYER_ADD1, #{detailCondition.buyerAdd1}) > 0
            </if>
            <if test="@org.apache.commons.lang3.StringUtils@isNotBlank(detailCondition.buyerName)">
                AND INSTR(BUYER_NAME, #{detailCondition.buyerName}) > 0
            </if>
        </if>
    </trim>
</sql>

 

simpleCondition 검색조건

<sql id="searchFrag">
    <where>
        <if test="simpleCondition neq null and @org.apache.commons.lang3.StringUtils@isNotBlank(simpleCondition.searchWord)">
            <choose>
                <when test="simpleCondition.searchType eq 'writer'">
                    INSTR(BO_WRITER, #{simpleCondition.searchWord}) > 0
                </when>
                <when test="simpleCondition.searchType eq 'content'">
                    INSTR(BO_CONTENT, #{simpleCondition.searchWord}) > 0
                </when>
                <otherwise>
                    INSTR(BO_WRITER, #{simpleCondition.searchWord}) > 0
                    OR
                    INSTR(BO_CONTENT, #{simpleCondition.searchWord}) > 0
                </otherwise>
            </choose>
        </if>
    </where>
</sql>
반응형