com.lone.common.util.CommonUtils Maven / Gradle / Ivy
The newest version!
package com.lone.common.util;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
public class CommonUtils {
/**
* 获得请求路径【注意: 不通用】
*
* @param request
* @return
*/
public static String getJgAuthRequsetPath(HttpServletRequest request) {
// String requestPath = request.getRequestURI() + "?" + request.getQueryString();
String queryString = request.getQueryString();
String requestPath = request.getRequestURI();
if(StringUtils.isNotEmpty(queryString)){
requestPath += "?" + queryString;
}
if (requestPath.indexOf("&") > -1) {// 去掉其他参数(保留一个参数) 例如:loginController.do?login
requestPath = requestPath.substring(0, requestPath.indexOf("&"));
}
if(requestPath.indexOf("=")!=-1){
if(requestPath.indexOf(".do")!=-1){
requestPath = requestPath.substring(0,requestPath.indexOf(".do")+3);
}else{
requestPath = requestPath.substring(0,requestPath.indexOf("?"));
}
}
requestPath = requestPath.substring(request.getContextPath().length() + 1);// 去掉项目路径
return requestPath;
}
/**
* 获得请求路径
*
* @param request
* @return
*/
public static String getRequestPath(HttpServletRequest request) {
String requestPath = request.getRequestURI();
if (request.getQueryString() != null) {
requestPath = requestPath + "?" + request.getQueryString();
}
if (requestPath.indexOf("&") > -1) {// 去掉其他参数
requestPath = requestPath.substring(0, requestPath.indexOf("&"));
}
requestPath = requestPath.substring(request.getContextPath().length() + 1);// 去掉项目路径
return requestPath;
}
// 冒泡算法,从大到小。
public static int[] seqFromBigtoSmall(int[] a) {
int temp;
for (int i = 0; i < a.length; i++) {
for (int j = a.length - 1; j > i; j--) {
if (a[j] > a[j - 1]) {
temp = a[j];
a[j] = a[j - 1];
a[j - 1] = temp;
}
}
}
return a;
}
/**
* 冒泡算法排序,从大到小。
*
* @param a
* @return
*/
public static int[] sortByBubble(int[] a) {
int temp;
for (int i = 0; i < a.length; i++) {
for (int j = a.length - 1; j > i; j--) {
if (a[j] > a[j - 1]) {
temp = a[j];
a[j] = a[j - 1];
a[j - 1] = temp;
}
}
}
return a;
}
}