提交 | 用户 | 时间
|
58d006
|
1 |
package com.mandi.dao.common; |
A |
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* @author mengly |
|
12 |
* @version 创建时间:2016年4月1日 下午5:30:17 |
|
13 |
* 类说明 |
|
14 |
*/ |
|
15 |
|
|
16 |
public class Sort implements Serializable { |
|
17 |
private static final long serialVersionUID = 1L; |
|
18 |
private List<String> ascFields; |
|
19 |
private List<String> descFields; |
|
20 |
public Sort() { |
|
21 |
ascFields=new ArrayList<String>(); |
|
22 |
descFields=new ArrayList<String>(); |
|
23 |
} |
|
24 |
|
|
25 |
public void addAscField(String field) |
|
26 |
{ |
|
27 |
this.ascFields.add(field); |
|
28 |
} |
|
29 |
public void addDescFields(String field) |
|
30 |
{ |
|
31 |
this.descFields.add(field); |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public String toString() { |
|
36 |
if(this.ascFields.isEmpty()&&this.descFields.isEmpty()) |
|
37 |
return ""; |
|
38 |
List<String> tstrs=new ArrayList<String>(); |
|
39 |
for (String string : ascFields) { |
|
40 |
tstrs.add(string+" asc"); |
|
41 |
} |
|
42 |
for (String string : descFields) { |
|
43 |
tstrs.add(string+" desc"); |
|
44 |
} |
|
45 |
if(tstrs.isEmpty()) |
|
46 |
return ""; |
|
47 |
String str=" order by "+StringUtils.join(tstrs, ","); |
|
48 |
return str; |
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
} |