我也没有找到任何相当于 UriInfo 的 spring 类。我使用如下代码:
private getRequstUrl(HttpServletRequest request) {
String requestUrl = request.getScheme() + "://" + request.getServerName()
+ ("http".equals(request.getScheme()) && request.getServerPort() == 80 || "https".equals(request.getScheme()) &&
request.getServerPort() == 443 ? "" : ":" + request.getServerPort())
+ request.getRequestURI();
return requestUrl;
}
public String constructLink(ParamModel paramModel, String requestUrl) {
StringBuilder stringBuilder = new StringBuilder("<");
stringBuilder.append(requestUrl);
if (paramModel.getSize() > 0 && paramModel.getStart() > -1) {
stringBuilder.append("?");
stringBuilder.append("start=");
stringBuilder.append(paramModel.getStart() + paramModel.getSize());
stringBuilder.append("&");
stringBuilder.append("size=");
stringBuilder.append(paramModel.getSize());
}
stringBuilder.append(">; rel=\"next\"");
return stringBuilder.toString();
}