1.后端获取ip地址的Java方法:
String clientIp = request.getHeader("x-forwarded-for");
if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
clientIp = request.getHeader("Proxy-Client-IP");
}
if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
clientIp = request.getHeader("WL-Proxy-Client-IP");
}
if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
clientIp = request.getRemoteAddr();
}
2.分页的基本类
package com.kd.nm.util;
/**
* 页面设置
* @author 25338
* @date 2019-12-3
*/
public class PageUtil {
private Integer currentPage;//当前页
private Integer counts;//总数量
private Integer pageSize;//总页数
private Integer pageCounts;//页容量
private Integer startSuffix;//开始下标
/**
* 页码
* @param currentPage 当前页
* @param counts 总数量
* @param pageCounts 页容量
*/
public PageUtil(Integer currentPage, Integer counts, Integer pageCounts) {
this.currentPage = currentPage;
this.counts = counts;
this.pageCounts = pageCounts;
this.pageSize=counts%pageCounts==0?counts/pageCounts:counts/pageCounts+1;
this.startSuffix=(currentPage-1)*pageCounts;
}
/**
* 初始化进入时
* @param pageCount
*/
public PageUtil(Integer pageCount) {
this.startSuffix=0;
this.pageCounts=pageCount;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getStartSuffix() {
if(startSuffix==null||startSuffix==0) {
return 1;
}
return startSuffix;
}
public void setStartSuffix(Integer startSuffix) {
this.startSuffix = startSuffix;
}
public Integer getCurrentPage() {
if(currentPage==null||currentPage==0) {
return 1;
}
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getCounts() {
return counts;
}
public void setCounts(Integer counts) {
this.counts = counts;
}
public Integer getPageCounts() {
return pageCounts;
}
public void setPageCounts(Integer pageCounts) {
this.pageCounts = pageCounts;
}
}