하석형 하석형 04-18
250418 하석형 Pagination SQL 검색 필드 추가 (와일드카드 이스케이프 처리), 권한SQL 검색 필드 변경
@9da6959a7a7feac7101ac423c01050db4dc12bae
src/main/java/com/takensoft/common/Pagination.java
--- src/main/java/com/takensoft/common/Pagination.java
+++ src/main/java/com/takensoft/common/Pagination.java
@@ -31,6 +31,7 @@
     
     private String searchType;      // 검색조건
     private String searchText;      // 검색어
+    private String sqlSearchText;   // SQL검색어 (이스케이프 처리된 검색어)
 
     private String startDt;         // 시작일
     private String endDt;           // 종료일
@@ -54,7 +55,11 @@
         this.recordSize = Integer.parseInt(params.getOrDefault("recordSize", "1"));
         this.pageSize = Integer.parseInt(params.getOrDefault("pageSize", "10"));
         this.searchType = (String)params.get("searchType");
-        this.searchText = (String)params.get("searchText");
+        String rawSearchText = (String)params.get("searchText");
+        this.searchText = rawSearchText;
+        this.sqlSearchText = rawSearchText != null
+                ? rawSearchText.replace("~", "~~").replace("_", "~_").replace("%", "~%")
+                : null; // SQL 검색 시 와일드카드 이스케이프 처리
         this.startDt = (String)params.get("startDt");
         this.endDt = (String)params.get("endDt");
         this.id = (String)params.get("id");
src/main/resources/mybatis/mapper/author/author-SQL.xml
--- src/main/resources/mybatis/mapper/author/author-SQL.xml
+++ src/main/resources/mybatis/mapper/author/author-SQL.xml
@@ -38,8 +38,8 @@
     </sql>
 
     <sql id="selectRequirement">
-        <if test="searchText != null and searchText != ''">
-            AND ai.authrt_nm LIKE '%' || #{searchText} || '%'
+        <if test="sqlSearchText != null and sqlSearchText != ''">
+            AND ai.authrt_nm LIKE '%' || #{sqlSearchText} || '%' ESCAPE '~'
         </if>
     </sql>
 
@@ -69,6 +69,7 @@
         WHERE 1=1
         <!--ai.use_yn = 'Y'-->
         <include refid="selectRequirement" />
+        ORDER BY ai.reg_dt DESC
         LIMIT #{recordSize} OFFSET #{limitStart}
     </select>
 
Add a comment
List