新增作者相关参数及接口
This commit is contained in:
@@ -49,6 +49,7 @@ public class FriendRouter {
|
||||
.flatMap( templateName -> ServerResponse.ok().render(templateName,
|
||||
java.util.Map.of(ModelConst.TEMPLATE_ID, templateName,
|
||||
"friends", friendPostList(request),
|
||||
"authors", friendFinder.listAllAuthors().collectList(),
|
||||
"title",getFriendTitle())
|
||||
));
|
||||
}
|
||||
@@ -65,6 +66,24 @@ public class FriendRouter {
|
||||
String linkName = request.queryParam("linkName")
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.orElse(null);
|
||||
// --- 新增:获取 author 参数 ---
|
||||
String author = request.queryParam("author")
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.orElse(null);
|
||||
|
||||
// --- 新增:构建查询参数字符串 ---
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
if (StringUtils.isNotBlank(linkName)) {
|
||||
queryString.append("linkName=").append(linkName);
|
||||
}
|
||||
if (StringUtils.isNotBlank(author)) {
|
||||
if (queryString.length() > 0) {
|
||||
queryString.append("&");
|
||||
}
|
||||
queryString.append("author=").append(author);
|
||||
}
|
||||
final String finalQueryString = queryString.toString();
|
||||
|
||||
return this.settingFetcher.get("base")
|
||||
.map(item -> item.get("pageSize").asInt(10))
|
||||
.defaultIfEmpty(10)
|
||||
@@ -75,20 +94,44 @@ public class FriendRouter {
|
||||
if(StringUtils.isNotBlank(linkName)){
|
||||
params.put("linkName",linkName);
|
||||
}
|
||||
// --- 新增:把 author 也放进 params ---
|
||||
if(StringUtils.isNotBlank(author)){
|
||||
params.put("author",author);
|
||||
}
|
||||
|
||||
return friendFinder.list(params)
|
||||
.map(list -> new UrlContextListResult.Builder<FriendPostVo>()
|
||||
.listResult(list)
|
||||
.nextUrl(PageUrlUtils.nextPageUrl(path, totalPage(list)))
|
||||
.prevUrl(PageUrlUtils.prevPageUrl(path))
|
||||
.build()
|
||||
);
|
||||
.map(list -> {
|
||||
// --- 修改:生成链接时带上查询参数 ---
|
||||
String baseNextUrl = PageUrlUtils.nextPageUrl(path, totalPage(list));
|
||||
String basePrevUrl = PageUrlUtils.prevPageUrl(path);
|
||||
|
||||
String nextUrl = appendQueryString(baseNextUrl, finalQueryString);
|
||||
String prevUrl = appendQueryString(basePrevUrl, finalQueryString);
|
||||
|
||||
return new UrlContextListResult.Builder<FriendPostVo>()
|
||||
.listResult(list)
|
||||
.nextUrl(nextUrl)
|
||||
.prevUrl(prevUrl)
|
||||
.build();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --- 新增:辅助方法,用于拼接查询参数 ---
|
||||
private String appendQueryString(String url, String queryString) {
|
||||
if (StringUtils.isBlank(queryString)) {
|
||||
return url;
|
||||
}
|
||||
if (url.contains("?")) {
|
||||
return url + "&" + queryString;
|
||||
} else {
|
||||
return url + "?" + queryString;
|
||||
}
|
||||
}
|
||||
|
||||
private int pageNumInPathVariable(ServerRequest request) {
|
||||
String page = request.pathVariables().get("page");
|
||||
return NumberUtils.toInt(page, 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user