values = new ArrayList<>(1);
-
- public QueryFieldListItem(String keyWord) {
- values.add(keyWord);
- }
- }
-}
\ No newline at end of file
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BaseLibraryApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BaseLibraryApiService.java
index 82ed014..69f34cd 100644
--- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BaseLibraryApiService.java
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BaseLibraryApiService.java
@@ -1,10 +1,51 @@
package cn.wustlinghang.mywust.core.request.service.library;
+import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook;
+import cn.wustlinghang.mywust.data.library.origin.BookSearchResult;
+import cn.wustlinghang.mywust.data.library.origin.CurrentLoanBook;
+import cn.wustlinghang.mywust.data.library.origin.HistoryLoanBook;
+import cn.wustlinghang.mywust.data.library.parsed.BookHolding;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.deser.std.StringDeserializer;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+import java.io.IOException;
+import java.util.List;
public abstract class BaseLibraryApiService {
+ protected static final ObjectMapper objectMapper = new ObjectMapper();
+
+ static {
+ objectMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ SimpleModule module = new SimpleModule();
+ module.addDeserializer(String.class, new SpecialStringDeserializer());
+ objectMapper.registerModule(module);
+ }
+
+ protected static final JavaType loanBookListType =
+ objectMapper.getTypeFactory().constructParametricType(List.class, BaseLoanBook.class);
+
+ protected static final JavaType historyLoanBookListType =
+ objectMapper.getTypeFactory().constructParametricType(List.class, HistoryLoanBook.class);
+
+ protected static final JavaType currentLoanBookListType =
+ objectMapper.getTypeFactory().constructParametricType(List.class, CurrentLoanBook.class);
+
+ protected static final JavaType bookSearchResultListType =
+ objectMapper.getTypeFactory().constructParametricType(List.class, BookSearchResult.class);
+
+ protected static final JavaType bookHoldingListType =
+ objectMapper.getTypeFactory().constructParametricType(List.class, BookHolding.class);
+
protected final Requester requester;
public BaseLibraryApiService(Requester requester) {
@@ -18,3 +59,24 @@ public abstract class BaseLibraryApiService {
}
}
}
+
+/**
+ * 继承自原版StringDeserializer,特殊定制的字符串反序列化器
+ * 测试时偶然发现的图书馆搜索api返回的json中`pub_year`和`abstract`等一些本应该是字符串值的字段有概率会出现为空数组的奇葩情况...
+ * 想了半天也没想明白那系统究竟是怎么在字符串里蹦出`[]`的...
+ */
+class SpecialStringDeserializer extends StringDeserializer {
+ @Override
+ public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
+ // The critical path: ensure we handle the common case first.
+ if (p.hasToken(JsonToken.VALUE_STRING)) {
+ return p.getText();
+ }
+ // [databind#381]
+ if (p.hasToken(JsonToken.START_ARRAY)) {
+ // 仅修改了这行
+ return p.getValueAsString("");
+ }
+ return _parseString(p, ctxt, this);
+ }
+}
\ No newline at end of file
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookCoverImageUrlApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookCoverImageUrlApiService.java
index 58c6349..3b2b85f 100644
--- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookCoverImageUrlApiService.java
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookCoverImageUrlApiService.java
@@ -5,19 +5,55 @@ import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
+import java.util.*;
public class BookCoverImageUrlApiService extends BaseLibraryApiService {
public BookCoverImageUrlApiService(Requester requester) {
super(requester);
}
- public String getBookCoverImageUrl(String isbn) throws ApiException, IOException {
+ public List getBookCoverImageUrl(String isbn) throws ApiException, IOException {
HttpRequest request = LibraryRequestFactory.bookCoverImageUrlRequest(isbn);
HttpResponse response = requester.get(request);
checkResponse(response);
- return response.getStringBody();
+ // 因为只查了一本书,所以path(isbn)直接一步到位就行了
+ JsonNode imageResultJson = objectMapper.readTree(response.getBody()).path("data").path(isbn);
+ List covers = new ArrayList<>(imageResultJson.size());
+ for (JsonNode resultItemJson : imageResultJson) {
+ covers.add(resultItemJson.path("imageUrl").asText()
+ .replaceAll("^//", "http://")
+ );
+ }
+
+ return covers;
+ }
+
+ public Map> getBookCoverImageUrl(List isbnList) throws ApiException, IOException {
+ HttpRequest request = LibraryRequestFactory.bookCoverImageUrlRequest(isbnList);
+ HttpResponse response = requester.get(request);
+ checkResponse(response);
+
+ JsonNode data = objectMapper.readTree(response.getBody()).path("data");
+ Map> result = new HashMap<>(data.size());
+
+ // 遍历data下每本书
+ Iterator> it = data.fields();
+ while (it.hasNext()) {
+ Map.Entry bookItemJson = it.next();
+ List covers = new ArrayList<>(bookItemJson.getValue().size());
+ for (JsonNode resultItemJson : bookItemJson.getValue()) {
+ covers.add(resultItemJson.path("imageUrl").asText()
+ .replaceAll("^//", "http://")
+ );
+ }
+
+ result.put(bookItemJson.getKey(), covers);
+ }
+
+ return result;
}
}
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookDetailApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookDetailApiService.java
index 1a23b6b..513d3ce 100644
--- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookDetailApiService.java
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookDetailApiService.java
@@ -1,24 +1,70 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
+import cn.wustlinghang.mywust.data.library.parsed.BookDetail;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import cn.wustlinghang.mywust.util.StringUtil;
+import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
public class BookDetailApiService extends BaseLibraryApiService {
public BookDetailApiService(Requester requester) {
super(requester);
}
- public String getBookDetail(String bookId) throws ApiException, IOException {
- HttpRequest request = LibraryRequestFactory.bookInfoRequest(bookId);
- HttpResponse response = requester.get(request);
- checkResponse(response);
+ public BookDetail getBookDetail(String bookId) throws ApiException, IOException {
+ HttpRequest infoRequest = LibraryRequestFactory.bookInfoRequest(bookId);
+ HttpResponse infoResponse = requester.get(infoRequest);
+ checkResponse(infoResponse);
- return response.getStringBody();
- }
+ JsonNode data = objectMapper.readTree(infoResponse.getBody())
+ .path("data").path("map");
+
+ JsonNode baseInfo = data.path("baseInfo").path("map");
+ JsonNode detailInfo = data.path("detailInfo").path("map");
+
+ Map extraInfoMap = new HashMap<>(detailInfo.size());
+ Iterator> it = detailInfo.fields();
+ while (it.hasNext()) {
+ Map.Entry field = it.next();
+ extraInfoMap.put(field.getKey(), StringUtil.cleanHtml(field.getValue().asText("无")));
+ }
+
+ String isbn = baseInfo.get("isbn").asText("无");
+ String author = baseInfo.path("author").asText("无");
+ String title = baseInfo.path("title").asText("无");
+
+ HttpRequest doubanInfoRequest = LibraryRequestFactory.bookDoubanInfoRequest(isbn);
+ HttpResponse doubanInfoResponse = requester.get(doubanInfoRequest);
+ checkResponse(doubanInfoResponse);
+ JsonNode doubanInfo = objectMapper.readTree(doubanInfoResponse.getBody()).path("data");
+ String authorDescribe = doubanInfo.path("authorInfo").asText("无");
+ String catalog = doubanInfo.path("catalog").asText("无");
+ String summary = doubanInfo.path("content").asText("无");
+ String introduction = doubanInfo.path("intro").asText(summary);
+ String coverUrl = doubanInfo.path("imageUrl").asText("")
+ .replaceAll("^//", "http://");
+
+ return BookDetail.builder()
+ .isbn(isbn)
+ .author(author)
+ .title(title)
+ .extraInfoMap(extraInfoMap)
+
+ .authorDescribe(StringUtil.cleanHtml(authorDescribe))
+ .catalog(StringUtil.cleanHtml(catalog))
+ .summary(StringUtil.cleanHtml(summary))
+ .introduction(StringUtil.cleanHtml(introduction))
+ .coverUrl(coverUrl)
+
+ .build();
+ }
}
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookHoldingApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookHoldingApiService.java
new file mode 100644
index 0000000..a8953ec
--- /dev/null
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/BookHoldingApiService.java
@@ -0,0 +1,39 @@
+package cn.wustlinghang.mywust.core.request.service.library;
+
+import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
+import cn.wustlinghang.mywust.data.library.parsed.BookHolding;
+import cn.wustlinghang.mywust.exception.ApiException;
+import cn.wustlinghang.mywust.exception.ParseException;
+import cn.wustlinghang.mywust.network.Requester;
+import cn.wustlinghang.mywust.network.entitys.HttpRequest;
+import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import com.fasterxml.jackson.core.JacksonException;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import java.io.IOException;
+import java.util.List;
+
+public class BookHoldingApiService extends BaseLibraryApiService {
+
+
+ public BookHoldingApiService(Requester requester) {
+ super(requester);
+ }
+
+ public List getHoldingList(String id)
+ throws ApiException, IOException, ParseException {
+
+ HttpRequest loanRequest = LibraryRequestFactory.bookHoldingRequest(id);
+ HttpResponse loanResponse = requester.get(loanRequest);
+ checkResponse(loanResponse);
+ try {
+ JsonNode data = objectMapper.readTree(loanResponse.getBody()).path("data");
+ // 这里的holding是个string值,需要独立解析(坑人)
+ JsonNode holdings = data.path("holdings");
+
+ return objectMapper.readValue(holdings.asText("[]"), bookHoldingListType);
+ } catch (JacksonException e) {
+ throw new ParseException(e.getMessage(), "");
+ }
+ }
+}
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/CurrentLoanApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/CurrentLoanApiService.java
index 19a461f..7d10067 100644
--- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/CurrentLoanApiService.java
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/CurrentLoanApiService.java
@@ -1,24 +1,52 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
+import cn.wustlinghang.mywust.data.library.PagingResult;
+import cn.wustlinghang.mywust.data.library.origin.CurrentLoanBook;
import cn.wustlinghang.mywust.exception.ApiException;
+import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import com.fasterxml.jackson.core.JacksonException;
+import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
+import java.util.List;
public class CurrentLoanApiService extends BaseLibraryApiService {
public CurrentLoanApiService(Requester requester) {
super(requester);
}
- public String getCurrentLoan(String cookie) throws ApiException, IOException {
- HttpRequest request = LibraryRequestFactory.currentLoanRequest(cookie);
- HttpResponse response = requester.get(request);
- checkResponse(response);
+ public PagingResult> getCurrentLoan(String cookie, int page, int pageSize)
+ throws ApiException, IOException, ParseException {
- return response.getStringBody();
- }
+ HttpRequest loanRequest = LibraryRequestFactory.currentLoanRequest(cookie, page, pageSize);
+ HttpResponse loanResponse = requester.get(loanRequest);
+ checkResponse(loanResponse);
+ try {
+ JsonNode data = objectMapper.readTree(loanResponse.getBody()).path("data");
+
+ // 获取,计算分页数据
+ pageSize = data.path("pageSize").asInt(pageSize);
+ int currentPage = data.path("currentPage").asInt(page);
+ int totalResult = data.path("total").asInt(0);
+ int totalPage = data.path("totalPage").asInt(0);
+
+ JsonNode itemsJson = data.path("items");
+ List books = objectMapper.treeToValue(itemsJson, currentLoanBookListType);
+ return PagingResult.>builder()
+ .currentPage(currentPage)
+ .totalResult(totalResult)
+ .pageSize(pageSize)
+ .totalPage(totalPage)
+ .data(books)
+ .build();
+
+ } catch (JacksonException e) {
+ throw new ParseException(e.getMessage(), "");
+ }
+ }
}
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/LoanHistoryApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/LoanHistoryApiService.java
index 1201a1f..d91bf5e 100644
--- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/LoanHistoryApiService.java
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/LoanHistoryApiService.java
@@ -1,23 +1,53 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
+import cn.wustlinghang.mywust.data.library.PagingResult;
+import cn.wustlinghang.mywust.data.library.origin.HistoryLoanBook;
import cn.wustlinghang.mywust.exception.ApiException;
+import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import com.fasterxml.jackson.core.JacksonException;
+import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
+import java.util.List;
public class LoanHistoryApiService extends BaseLibraryApiService {
+
public LoanHistoryApiService(Requester requester) {
super(requester);
}
- public String getLoanHistory(String cookie) throws ApiException, IOException {
- HttpRequest request = LibraryRequestFactory.loanHistoryRequest(cookie);
+ public PagingResult> getLoanHistory(String cookie, int page, int pageSize)
+ throws ApiException, IOException, ParseException {
+
+ HttpRequest request = LibraryRequestFactory.loanHistoryRequest(cookie, page, pageSize);
HttpResponse response = requester.get(request);
checkResponse(response);
+ try {
+ JsonNode data = objectMapper.readTree(response.getBody()).path("data");
+
+ // 获取,计算分页数据
+ pageSize = data.path("pageSize").asInt(pageSize);
+ int currentPage = data.path("currentPage").asInt(page);
+ int totalResult = data.path("total").asInt(0);
+ int totalPage = data.path("totalPage").asInt(0);
+
+ JsonNode itemsJson = data.path("items");
+ List books = objectMapper.treeToValue(itemsJson, historyLoanBookListType);
+
+ return PagingResult.>builder()
+ .currentPage(currentPage)
+ .totalResult(totalResult)
+ .pageSize(pageSize)
+ .totalPage(totalPage)
+ .data(books)
+ .build();
- return response.getStringBody();
+ } catch (JacksonException e) {
+ throw new ParseException(e.getMessage(), "");
+ }
}
}
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/OverdueSoonApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/OverdueSoonApiService.java
index 578feb0..56ffbe8 100644
--- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/OverdueSoonApiService.java
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/OverdueSoonApiService.java
@@ -1,23 +1,56 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
+import cn.wustlinghang.mywust.data.library.PagingResult;
+import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook;
import cn.wustlinghang.mywust.exception.ApiException;
+import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import com.fasterxml.jackson.core.JacksonException;
+import com.fasterxml.jackson.databind.JsonNode;
+import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
+import java.util.List;
+@Slf4j
public class OverdueSoonApiService extends BaseLibraryApiService {
public OverdueSoonApiService(Requester requester) {
super(requester);
}
- public String getOverdueSoon(String cookie) throws ApiException, IOException {
- HttpRequest request = LibraryRequestFactory.overdueSoonRequest(cookie);
+ public PagingResult> getOverdueSoon(String cookie, int page, int pageSize)
+ throws ApiException, IOException, ParseException {
+
+ HttpRequest request = LibraryRequestFactory.overdueSoonRequest(cookie, page, pageSize);
HttpResponse response = requester.get(request);
checkResponse(response);
+ try {
+ // todo 这里即将到期书籍字段跟当前借阅和借阅历史字段格式貌似有点不太一样(data字段是个数组)
+ // 但是目前手上没有样本,因此这里还需要再测试测试
+ JsonNode data = objectMapper.readTree(response.getBody()).path("data");
+
+ // 获取,计算分页数据
+ pageSize = data.path("pageSize").asInt(pageSize);
+ int currentPage = data.path("currentPage").asInt(page);
+ int totalResult = data.path("total").asInt(0);
+ int totalPage = data.path("totalPage").asInt(0);
+
+ JsonNode itemsJson = data.path("items");
+ List baseLoanBooks = objectMapper.treeToValue(itemsJson, loanBookListType);
+
+ return PagingResult.>builder()
+ .currentPage(currentPage)
+ .totalResult(totalResult)
+ .pageSize(pageSize)
+ .totalPage(totalPage)
+ .data(baseLoanBooks)
+ .build();
- return response.getStringBody();
+ } catch (JacksonException e) {
+ throw new ParseException(e.getMessage(), "");
+ }
}
}
diff --git a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/SearchApiService.java b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/SearchApiService.java
index 07c5447..8b0eea3 100644
--- a/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/SearchApiService.java
+++ b/mywust-core/src/main/java/cn/wustlinghang/mywust/core/request/service/library/SearchApiService.java
@@ -1,24 +1,68 @@
package cn.wustlinghang.mywust.core.request.service.library;
import cn.wustlinghang.mywust.core.request.factory.library.LibraryRequestFactory;
+import cn.wustlinghang.mywust.data.library.PagingResult;
+import cn.wustlinghang.mywust.data.library.origin.BookSearchRequest;
+import cn.wustlinghang.mywust.data.library.origin.BookSearchResult;
+import cn.wustlinghang.mywust.data.library.parsed.BookHolding;
import cn.wustlinghang.mywust.exception.ApiException;
+import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.entitys.HttpRequest;
import cn.wustlinghang.mywust.network.entitys.HttpResponse;
+import com.fasterxml.jackson.core.JacksonException;
+import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
public class SearchApiService extends BaseLibraryApiService {
public SearchApiService(Requester requester) {
super(requester);
}
- public String search(String keyword, int page, int pageSize) throws ApiException, IOException {
- HttpRequest request = LibraryRequestFactory.bookSearchRequest(keyword, page, pageSize);
- HttpResponse response = requester.post(request);
- checkResponse(response);
-
- return response.getStringBody();
+ public PagingResult> search(String keyword, int page, int pageSize)
+ throws ApiException, IOException, ParseException {
+ return search(new BookSearchRequest(keyword, pageSize, page));
}
+ public PagingResult> search(BookSearchRequest request)
+ throws ApiException, IOException, ParseException {
+ HttpRequest searchRequest = LibraryRequestFactory.bookSearchRequest(request);
+ HttpResponse searchResponse = requester.post(searchRequest);
+ checkResponse(searchResponse);
+
+ try {
+ JsonNode data = objectMapper.readTree(searchResponse.getBody()).path("data");
+
+ int pageSize = data.path("limit").asInt(request.getPageSize());
+ int currentPage = data.path("offset").asInt(request.getPage()) / pageSize + 1;
+ int totalResult = data.path("actualTotal").asInt(0);
+ int totalPage = totalResult / pageSize + 1;
+
+ JsonNode dataList = data.get("dataList");
+ List books = new ArrayList<>(dataList.size());
+ for (JsonNode item : dataList) {
+ // 反序列化holding字段,原字段为字符串值,无法直接原样转换
+ List holdings = objectMapper.readValue(
+ item.path("holdings").asText("[]"), bookHoldingListType);
+ BookSearchResult book = objectMapper.treeToValue(item, BookSearchResult.class);
+ book.setHoldings(holdings);
+ books.add(book);
+ }
+
+ return PagingResult.>builder()
+ .currentPage(currentPage)
+ .totalResult(totalResult)
+ .pageSize(pageSize)
+ .totalPage(totalPage)
+ .data(books)
+ .build();
+
+ } catch (JacksonException e) {
+ e.printStackTrace();
+ throw new ParseException(e.getMessage(), "");
+ }
+ }
}
diff --git a/mywust-util/src/main/java/cn/wustlinghang/mywust/util/StringUtil.java b/mywust-util/src/main/java/cn/wustlinghang/mywust/util/StringUtil.java
index 2fe5f38..97f7934 100644
--- a/mywust-util/src/main/java/cn/wustlinghang/mywust/util/StringUtil.java
+++ b/mywust-util/src/main/java/cn/wustlinghang/mywust/util/StringUtil.java
@@ -110,4 +110,29 @@ public class StringUtil {
return result;
}
+
+ /**
+ * 清除字符串中的html(xml)标签,其中`<br>`被替换为换行`\n`
+ *
+ * @param raw 原始字符串
+ * @return 处理后的字符串
+ */
+ public static String cleanHtml(String raw) {
+ return cleanHtml(raw, true);
+ }
+
+ /**
+ * 清除字符串中的html(xml)标签,并指定`<br>`是否要替换为换行符`\n`
+ *
+ * @param raw 原始字符串
+ * @param withBreakLine 是否将换行标签`<br>`替换成换行符`\n`
+ * @return 处理后的字符串
+ */
+ public static String cleanHtml(String raw, boolean withBreakLine) {
+ if (withBreakLine) {
+ raw = raw.replaceAll("
", "\n");
+ }
+
+ return raw.replaceAll("<.*?>", "");
+ }
}
diff --git a/pom.xml b/pom.xml
index 2a61e79..93485c9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
- 0.0.2-SNAPSHOT
+ 0.0.2-beta
1.18.22