woals
08-06
240806 권민수 단어장 목록 조회 기능에 페이지네이션 추가
@6dca3d5bc7b020d58abd045d2e495bd1e222f67f
--- src/main/java/com/takensoft/ai_lms/lms/word_book/dao/WordBookDAO.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/dao/WordBookDAO.java
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 |
import com.takensoft.ai_lms.lms.word_book.vo.WordBookVO; |
4 | 4 |
import org.egovframe.rte.psl.dataaccess.mapper.Mapper; |
5 | 5 |
|
6 |
+import java.util.HashMap; |
|
6 | 7 |
import java.util.List; |
7 | 8 |
|
8 | 9 |
/** |
... | ... | @@ -16,10 +17,12 @@ |
16 | 17 |
public interface WordBookDAO { |
17 | 18 |
|
18 | 19 |
// 임시: 단어장 전체 목록 조회 |
19 |
- List<WordBookVO> getAllWordBooks(); |
|
20 |
+ List<WordBookVO> getAllWordBooks(HashMap<String, Object> params) throws Exception; |
|
21 |
+ int getWordBooksCount() throws Exception; |
|
20 | 22 |
|
21 | 23 |
// 책에 소속된 단어장 목록 조회 |
22 |
- List<WordBookVO> getWordBooksByBookId(String bookId); |
|
24 |
+ List<WordBookVO> getWordBooksByBookId(HashMap<String, Object> params) throws Exception; |
|
25 |
+ int getWordBooksByBookIdCount(String bookId) throws Exception; |
|
23 | 26 |
|
24 | 27 |
// 아이디에 해당하는 단어장 조회 |
25 | 28 |
WordBookVO getWordBookById(String wdBookId); |
... | ... | @@ -34,9 +37,11 @@ |
34 | 37 |
int deleteWordBook(String wdBookId); |
35 | 38 |
|
36 | 39 |
// 단어장 검색(지문 이름으로 검색) |
37 |
- List<WordBookVO> getWordBooksByTextTitle(String textTitle); |
|
40 |
+ List<WordBookVO> getWordBooksByTextTitle(HashMap<String, Object> params) throws Exception; |
|
41 |
+ int getWordBooksByTextTitleCount(String textTitle) throws Exception; |
|
38 | 42 |
|
39 | 43 |
// 단어장 검색(단어로 검색) |
40 |
- List<WordBookVO> getWordBooksByWord(String word); |
|
44 |
+ List<WordBookVO> getWordBooksByWord(HashMap<String, Object> params) throws Exception; |
|
45 |
+ int getWordBooksByWordCount(String word) throws Exception; |
|
41 | 46 |
|
42 | 47 |
} |
--- src/main/java/com/takensoft/ai_lms/lms/word_book/service/Impl/WordBookServiceImpl.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/service/Impl/WordBookServiceImpl.java
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 |
import lombok.RequiredArgsConstructor; |
8 | 8 |
import org.springframework.stereotype.Service; |
9 | 9 |
|
10 |
+import java.util.HashMap; |
|
10 | 11 |
import java.util.List; |
11 | 12 |
|
12 | 13 |
/** |
... | ... | @@ -25,13 +26,32 @@ |
25 | 26 |
private final IdgenService wordBookIdgn; |
26 | 27 |
|
27 | 28 |
@Override |
28 |
- public List<WordBookVO> getAllWordBooks() { |
|
29 |
- return wordBookDAO.getAllWordBooks(); |
|
29 |
+ public List<WordBookVO> getAllWordBooks(int page, int pageSize) throws Exception { |
|
30 |
+ int startIndex = (page - 1) * pageSize; |
|
31 |
+ HashMap<String, Object> params = new HashMap<>(); |
|
32 |
+ params.put("startIndex", startIndex); |
|
33 |
+ params.put("pageSize", pageSize); |
|
34 |
+ return wordBookDAO.getAllWordBooks(params); |
|
30 | 35 |
} |
31 | 36 |
|
32 | 37 |
@Override |
33 |
- public List<WordBookVO> getWordBooksByBookId(String bookId) { |
|
34 |
- return wordBookDAO.getWordBooksByBookId(bookId); |
|
38 |
+ public int getWordBooksCount() throws Exception { |
|
39 |
+ return wordBookDAO.getWordBooksCount(); |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ @Override |
|
43 |
+ public List<WordBookVO> getWordBooksByBookId(String bookId, int page, int pageSize) throws Exception { |
|
44 |
+ int startIndex = (page - 1) * pageSize; |
|
45 |
+ HashMap<String, Object> params = new HashMap<>(); |
|
46 |
+ params.put("bookId", bookId); |
|
47 |
+ params.put("startIndex", startIndex); |
|
48 |
+ params.put("pageSize", pageSize); |
|
49 |
+ return wordBookDAO.getWordBooksByBookId(params); |
|
50 |
+ } |
|
51 |
+ |
|
52 |
+ @Override |
|
53 |
+ public int getWordBooksByBookIdCount(String bookId) throws Exception { |
|
54 |
+ return wordBookDAO.getWordBooksByBookIdCount(bookId); |
|
35 | 55 |
} |
36 | 56 |
|
37 | 57 |
@Override |
... | ... | @@ -57,13 +77,33 @@ |
57 | 77 |
} |
58 | 78 |
|
59 | 79 |
@Override |
60 |
- public List<WordBookVO> getWordBooksByTextTitle(String textTitle) { |
|
61 |
- return wordBookDAO.getWordBooksByTextTitle(textTitle); |
|
80 |
+ public List<WordBookVO> getWordBooksByTextTitle(String textTitle, int page, int pageSize) throws Exception { |
|
81 |
+ int startIndex = (page - 1) * pageSize; |
|
82 |
+ HashMap<String, Object> params = new HashMap<>(); |
|
83 |
+ params.put("textTitle", "%" + textTitle + "%"); |
|
84 |
+ params.put("startIndex", startIndex); |
|
85 |
+ params.put("pageSize", pageSize); |
|
86 |
+ return wordBookDAO.getWordBooksByTextTitle(params); |
|
62 | 87 |
} |
63 | 88 |
|
64 | 89 |
@Override |
65 |
- public List<WordBookVO> getWordBooksByWord(String word) { |
|
66 |
- return wordBookDAO.getWordBooksByWord(word); |
|
90 |
+ public int getWordBooksByTextTitleCount(String textTitle) throws Exception { |
|
91 |
+ return wordBookDAO.getWordBooksByTextTitleCount(textTitle); |
|
92 |
+ } |
|
93 |
+ |
|
94 |
+ @Override |
|
95 |
+ public List<WordBookVO> getWordBooksByWord(String word, int page, int pageSize) throws Exception { |
|
96 |
+ int startIndex = (page - 1) * pageSize; |
|
97 |
+ HashMap<String, Object> params = new HashMap<>(); |
|
98 |
+ params.put("word", "%" + word + "%"); |
|
99 |
+ params.put("startIndex", startIndex); |
|
100 |
+ params.put("pageSize", pageSize); |
|
101 |
+ return wordBookDAO.getWordBooksByWord(params); |
|
102 |
+ } |
|
103 |
+ |
|
104 |
+ @Override |
|
105 |
+ public int getWordBooksByWordCount(String word) throws Exception { |
|
106 |
+ return wordBookDAO.getWordBooksByWordCount(word); |
|
67 | 107 |
} |
68 | 108 |
|
69 | 109 |
} |
--- src/main/java/com/takensoft/ai_lms/lms/word_book/service/WordBookService.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/service/WordBookService.java
... | ... | @@ -14,10 +14,12 @@ |
14 | 14 |
public interface WordBookService { |
15 | 15 |
|
16 | 16 |
// 임시: 단어장 전체 목록 조회 |
17 |
- List<WordBookVO> getAllWordBooks(); |
|
17 |
+ List<WordBookVO> getAllWordBooks(int page, int pageSize) throws Exception; |
|
18 |
+ int getWordBooksCount() throws Exception; |
|
18 | 19 |
|
19 | 20 |
// 책에 소속된 단어장 목록 조회 |
20 |
- List<WordBookVO> getWordBooksByBookId(String bookId); |
|
21 |
+ List<WordBookVO> getWordBooksByBookId(String bookId, int page, int pageSize) throws Exception; |
|
22 |
+ int getWordBooksByBookIdCount(String bookId) throws Exception; |
|
21 | 23 |
|
22 | 24 |
// 아이디에 해당하는 단어장 조회 |
23 | 25 |
WordBookVO getWordBookById(String wdBookId); |
... | ... | @@ -32,10 +34,12 @@ |
32 | 34 |
void deleteWordBook(String wdBookId); |
33 | 35 |
|
34 | 36 |
// 단어장 검색(지문 이름으로 검색) |
35 |
- List<WordBookVO> getWordBooksByTextTitle(String textTitle); |
|
37 |
+ List<WordBookVO> getWordBooksByTextTitle(String textTitle, int page, int pageSize) throws Exception; |
|
38 |
+ int getWordBooksByTextTitleCount(String textTitle) throws Exception; |
|
36 | 39 |
|
37 | 40 |
// 단어장 검색(단어로 검색) |
38 |
- List<WordBookVO> getWordBooksByWord(String word); |
|
41 |
+ List<WordBookVO> getWordBooksByWord(String word, int page, int pageSize) throws Exception; |
|
42 |
+ int getWordBooksByWordCount(String word) throws Exception; |
|
39 | 43 |
|
40 | 44 |
|
41 | 45 |
} |
--- src/main/java/com/takensoft/ai_lms/lms/word_book/web/WordBookController.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/web/WordBookController.java
... | ... | @@ -6,6 +6,7 @@ |
6 | 6 |
import lombok.extern.slf4j.Slf4j; |
7 | 7 |
import org.springframework.web.bind.annotation.*; |
8 | 8 |
|
9 |
+import java.util.HashMap; |
|
9 | 10 |
import java.util.List; |
10 | 11 |
import java.util.Map; |
11 | 12 |
|
... | ... | @@ -26,15 +27,35 @@ |
26 | 27 |
|
27 | 28 |
// 단어장 전체 목록 조회 |
28 | 29 |
@PostMapping("/findAll.json") |
29 |
- public List<WordBookVO> getAllWordBooks() { |
|
30 |
- return wordBookService.getAllWordBooks(); |
|
30 |
+ public HashMap<String, Object> getAllWordBooks(@RequestBody HashMap<String, Object> params) throws Exception { |
|
31 |
+ int page = (int) params.get("page"); |
|
32 |
+ int pageSize = (int) params.get("pageSize"); |
|
33 |
+ |
|
34 |
+ List<WordBookVO> wordBooks = wordBookService.getAllWordBooks(page, pageSize); |
|
35 |
+ int totalWordBooks = wordBookService.getWordBooksCount(); |
|
36 |
+ |
|
37 |
+ HashMap<String, Object> result = new HashMap<>(); |
|
38 |
+ result.put("wordBooks", wordBooks); |
|
39 |
+ result.put("totalWordBooks", totalWordBooks); |
|
40 |
+ |
|
41 |
+ return result; |
|
31 | 42 |
} |
32 | 43 |
|
33 | 44 |
// 책에 소속된 단어장 목록 조회 |
34 | 45 |
@PostMapping("/findByBookId.json") |
35 |
- public List<WordBookVO> getWordBooksByBookId(@RequestBody Map<String, String> request) { |
|
36 |
- String bookId = request.get("bookId"); |
|
37 |
- return wordBookService.getWordBooksByBookId(bookId); |
|
46 |
+ public HashMap<String, Object> getWordBooksByBookId(@RequestBody HashMap<String, Object> params) throws Exception { |
|
47 |
+ String bookId = (String) params.get("bookId"); |
|
48 |
+ int page = (int) params.get("page"); |
|
49 |
+ int pageSize = (int) params.get("pageSize"); |
|
50 |
+ |
|
51 |
+ List<WordBookVO> wordBooks = wordBookService.getWordBooksByBookId(bookId, page, pageSize); |
|
52 |
+ int totalWordBooks = wordBookService.getWordBooksByBookIdCount(bookId); |
|
53 |
+ |
|
54 |
+ HashMap<String, Object> result = new HashMap<>(); |
|
55 |
+ result.put("wordBooks", wordBooks); |
|
56 |
+ result.put("totalWordBooks", totalWordBooks); |
|
57 |
+ |
|
58 |
+ return result; |
|
38 | 59 |
} |
39 | 60 |
|
40 | 61 |
// 아이디에 해당하는 단어장 조회 |
... | ... | @@ -68,15 +89,36 @@ |
68 | 89 |
|
69 | 90 |
// 단어장 검색(지문 이름으로 검색) |
70 | 91 |
@PostMapping("/findByTextTitle.json") |
71 |
- public List<WordBookVO> getWordBooksByTextTitle(@RequestBody Map<String, String> request) { |
|
72 |
- String textTitle = "%" + request.get("textTitle") + "%"; // 부분 검색 허용 |
|
73 |
- return wordBookService.getWordBooksByTextTitle(textTitle); |
|
92 |
+ public HashMap<String, Object> getWordBooksByTextTitle(@RequestBody HashMap<String, Object> params) throws Exception { |
|
93 |
+ String textTitle = (String) params.get("textTitle"); |
|
94 |
+ int page = (int) params.get("page"); |
|
95 |
+ int pageSize = (int) params.get("pageSize"); |
|
96 |
+ |
|
97 |
+ List<WordBookVO> wordBooks = wordBookService.getWordBooksByTextTitle(textTitle, page, pageSize); |
|
98 |
+ int totalWordBooks = wordBookService.getWordBooksByTextTitleCount(textTitle); |
|
99 |
+ |
|
100 |
+ HashMap<String, Object> result = new HashMap<>(); |
|
101 |
+ result.put("wordBooks", wordBooks); |
|
102 |
+ result.put("totalWordBooks", totalWordBooks); |
|
103 |
+ |
|
104 |
+ return result; |
|
74 | 105 |
} |
75 | 106 |
|
76 | 107 |
// 단어장 검색(단어로 검색) |
77 | 108 |
@PostMapping("/findByWord.json") |
78 |
- public List<WordBookVO> getWordBooksByWord(@RequestBody Map<String, String> request) { |
|
79 |
- return wordBookService.getWordBooksByWord(request.get("word")); |
|
109 |
+ public HashMap<String, Object> getWordBooksByWord(@RequestBody HashMap<String, Object> params) throws Exception { |
|
110 |
+ String word = (String) params.get("word"); |
|
111 |
+ int page = (int) params.get("page"); |
|
112 |
+ int pageSize = (int) params.get("pageSize"); |
|
113 |
+ |
|
114 |
+ List<WordBookVO> wordBooks = wordBookService.getWordBooksByWord(word, page, pageSize); |
|
115 |
+ int totalWordBooks = wordBookService.getWordBooksByWordCount(word); |
|
116 |
+ |
|
117 |
+ HashMap<String, Object> result = new HashMap<>(); |
|
118 |
+ result.put("wordBooks", wordBooks); |
|
119 |
+ result.put("totalWordBooks", totalWordBooks); |
|
120 |
+ |
|
121 |
+ return result; |
|
80 | 122 |
} |
81 | 123 |
|
82 | 124 |
} |
--- src/main/resources/mybatis/mapper/lms/word_book-SQL.xml
+++ src/main/resources/mybatis/mapper/lms/word_book-SQL.xml
... | ... | @@ -16,6 +16,31 @@ |
16 | 16 |
<result property="bookId" column="book_id"/> |
17 | 17 |
</resultMap> |
18 | 18 |
|
19 |
+ <select id="getWordBooksCount" resultType="int"> |
|
20 |
+ SELECT COUNT(*) |
|
21 |
+ FROM ai_lms.wordbook |
|
22 |
+ </select> |
|
23 |
+ |
|
24 |
+ <select id="getWordBooksByBookIdCount" resultType="int"> |
|
25 |
+ SELECT COUNT(*) |
|
26 |
+ FROM wordbook |
|
27 |
+ WHERE book_id = #{bookId} |
|
28 |
+ </select> |
|
29 |
+ |
|
30 |
+ <select id="getWordBooksByTextTitleCount" resultType="int"> |
|
31 |
+ SELECT COUNT(*) |
|
32 |
+ FROM wordbook wb |
|
33 |
+ JOIN text t ON wb.text_id = t.text_id |
|
34 |
+ WHERE t.text_ttl LIKE #{textTitle} |
|
35 |
+ </select> |
|
36 |
+ |
|
37 |
+ <select id="getWordBooksByWordCount" resultType="int"> |
|
38 |
+ SELECT COUNT(DISTINCT wb.wd_book_id) |
|
39 |
+ FROM wordbook wb |
|
40 |
+ JOIN word w ON wb.wd_book_id = w.wd_book_id |
|
41 |
+ WHERE w.wd_nm LIKE #{word} |
|
42 |
+ </select> |
|
43 |
+ |
|
19 | 44 |
<select id="getAllWordBooks" resultMap="WordBookResultMap"> |
20 | 45 |
SELECT |
21 | 46 |
wd_book_id, |
... | ... | @@ -24,9 +49,11 @@ |
24 | 49 |
user_id, |
25 | 50 |
book_id |
26 | 51 |
FROM ai_lms.wordbook |
52 |
+ ORDER BY wd_book_id DESC |
|
53 |
+ LIMIT #{pageSize} OFFSET #{startIndex} |
|
27 | 54 |
</select> |
28 | 55 |
|
29 |
- <select id="getWordBooksByBookId" resultMap="WordBookResultMap"> <!-- 수정됨 --> |
|
56 |
+ <select id="getWordBooksByBookId" resultMap="WordBookResultMap"> |
|
30 | 57 |
SELECT |
31 | 58 |
wd_book_id, |
32 | 59 |
wd_book_type_id, |
... | ... | @@ -35,6 +62,8 @@ |
35 | 62 |
book_id |
36 | 63 |
FROM wordbook |
37 | 64 |
WHERE book_id = #{bookId} |
65 |
+ ORDER BY wd_book_id DESC |
|
66 |
+ LIMIT #{pageSize} OFFSET #{startIndex} |
|
38 | 67 |
</select> |
39 | 68 |
|
40 | 69 |
<select id="getWordBookById" parameterType="string" resultMap="WordBookResultMap"> |
... | ... | @@ -81,6 +110,8 @@ |
81 | 110 |
FROM wordbook wb |
82 | 111 |
JOIN text t ON wb.text_id = t.text_id |
83 | 112 |
WHERE t.text_ttl LIKE #{textTitle} |
113 |
+ ORDER BY wd_book_id DESC |
|
114 |
+ LIMIT #{pageSize} OFFSET #{startIndex} |
|
84 | 115 |
</select> |
85 | 116 |
|
86 | 117 |
<select id="getWordBooksByWord" resultType="WordBookVO"> |
... | ... | @@ -88,6 +119,8 @@ |
88 | 119 |
FROM wordbook wb |
89 | 120 |
JOIN word w ON wb.wd_book_id = w.wd_book_id |
90 | 121 |
WHERE w.wd_nm LIKE #{word} |
122 |
+ ORDER BY wd_book_id DESC |
|
123 |
+ LIMIT #{pageSize} OFFSET #{startIndex} |
|
91 | 124 |
</select> |
92 | 125 |
|
93 | 126 |
</mapper>(파일 끝에 줄바꿈 문자 없음) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?