//根据上架时间、价格、销量升、降序排序price-desc sell-asc
if(order.getOrderMap()!=null){
Map<String, String> map = order.getOrderMap();
String orderName = map.get(CommonConstant.QUERYPARAMS_KEY_ORDERNAME);
if(!StringUtil.isNull(orderName)){
String[] orderParam = orderName.split(CommonConstant.QUERYPARAMS_KEY_SPLIT_MARK);
if(orderParam!=null && orderParam.length>1){
String order_key = orderParam[0];
String order_value = orderParam[1];
if(order_key.equals("commentLevel")){//其他排序
sqlBuffer.append(" order by sp." + order_key + "/sp.commentCount " + order_value);
}else {
sqlBuffer.append(" order by sp." + order_key + " " + order_value);
}
}
}
if(order.getOrderMap()!=null){
Map<String, String> map = order.getOrderMap();
String orderName = map.get(CommonConstant.QUERYPARAMS_KEY_ORDERNAME);
if(!StringUtil.isNull(orderName)){
String[] orderParam = orderName.split(CommonConstant.QUERYPARAMS_KEY_SPLIT_MARK);
if(orderParam!=null && orderParam.length>1){
String order_key = orderParam[0];
String order_value = orderParam[1];
if(order_key.equals("commentLevel")){//其他排序
sqlBuffer.append(" order by sp." + order_key + "/sp.commentCount " + order_value);
}else {
sqlBuffer.append(" order by sp." + order_key + " " + order_value);
}
}
}
}
分页查询
public static int countTotalPage(final int pageSize, final int allRow) {
int totalPage = allRow % pageSize == 0 ? allRow / pageSize : allRow
/ pageSize + 1;
return totalPage;
}
/***************************************************************************
*
* 计算当前页第一条元素的下标
* pageSize 每页记录数 currentPage 当前第几页
* @return 当前页开始记录号
*/
public static int countOffset(final int pageSize, final int currentPage) {
final int offset = pageSize * (currentPage - 1);
return offset;
}