jiapeng 8 jaren geleden
bovenliggende
commit
1d8a620db7

+ 2 - 0
jfwAptWeb/src/main/java/org/jfw/apt/web/AptWebHandler.java

@ -26,6 +26,7 @@ import org.jfw.apt.web.handlers.BuildParamHandler;
26 26
import org.jfw.apt.web.handlers.ChangeResultHandler;
27 27
import org.jfw.apt.web.handlers.CharacterEncodingHandler;
28 28
import org.jfw.apt.web.handlers.ExecuteHandler;
29
import org.jfw.apt.web.handlers.InvalidSessionHandler;
29 30
import org.jfw.apt.web.handlers.JdbcConnectionHandler;
30 31
import org.jfw.apt.web.handlers.LastScriptHandler;
31 32
import org.jfw.apt.web.handlers.LoginUserHandler;
@ -363,6 +364,7 @@ public class AptWebHandler extends CodeGenHandler {
363 364
		supportedClass.add(ExecuteHandler.class);
364 365
		supportedClass.add(SetSessionHandler.class);
365 366
		supportedClass.add(SetCookieHandler.class);
367
		supportedClass.add(InvalidSessionHandler.class);
366 368
		supportedClass.add(ChangeResultHandler.class);
367 369
		supportedClass.add(LastScriptHandler.class);
368 370
		supportedClass.add(ResultToNullHandler.class);

+ 11 - 0
jfwAptWeb/src/main/java/org/jfw/apt/web/annotation/method/InvalidSession.java

@ -0,0 +1,11 @@
1
package org.jfw.apt.web.annotation.method;
2

3
import java.lang.annotation.ElementType;
4
import java.lang.annotation.Retention;
5
import java.lang.annotation.RetentionPolicy;
6
import java.lang.annotation.Target;
7

8
@Target(ElementType.METHOD)
9
@Retention(RetentionPolicy.SOURCE)
10
public @interface InvalidSession {
11
}

+ 21 - 0
jfwAptWeb/src/main/java/org/jfw/apt/web/handlers/InvalidSessionHandler.java

@ -0,0 +1,21 @@
1
package org.jfw.apt.web.handlers;
2

3
import org.jfw.apt.exception.AptException;
4
import org.jfw.apt.out.ClassWriter;
5
import org.jfw.apt.web.RequestHandler;
6
import org.jfw.apt.web.annotation.method.InvalidSession;
7

8
public class InvalidSessionHandler  extends RequestHandler {
9

10
	@Override
11
	public void init() {
12
	}
13
	@Override
14
	public void appendBeforCode(ClassWriter cw) throws AptException {
15
		InvalidSession ss = this.aptWebHandler.getMe().getRef().getAnnotation(InvalidSession.class);
16
		if(ss!=null){
17
			this.aptWebHandler.readSession();
18
			cw.l("session.invalidate();");
19
		}
20
	}
21
}

+ 42 - 5
jfwUtil/src/main/java/org/jfw/util/PageQueryResult.java

@ -7,35 +7,72 @@ public class PageQueryResult<T> {
7 7
	private int total;
8 8
	private int pageNo = 1;
9 9
	private int pageSize;
10
	
10
11 11
	public int getTotal() {
12 12
		return total;
13 13
	}
14
14 15
	public void setTotal(int total) {
15 16
		this.total = total;
16 17
	}
18
17 19
	public int getPageNo() {
18 20
		return pageNo;
19 21
	}
22
20 23
	public void setPageNo(int pageNo) {
21 24
		this.pageNo = pageNo;
22 25
	}
26
23 27
	public int getPageSize() {
24 28
		return pageSize;
25 29
	}
30
26 31
	public void setPageSize(int pageSize) {
27 32
		this.pageSize = pageSize;
28 33
	}
34
29 35
	public List<T> getData() {
30 36
		return data;
31 37
	}
38
32 39
	public void setData(List<T> data) {
33 40
		this.data = data;
34 41
	}
42
35 43
	private List<T> data;
36
	
37
	public static void main(String[] args){
38
		new PageQueryResult<String>().setData(Collections.<String>emptyList());
39
		
44
45
	public static <T> PageQueryResult<T> build(List<T> list, int pageSize, int pageNo) {
46
		PageQueryResult<T> ret = new PageQueryResult<T>();
47
		ret.setTotal(list.size());
48
		pageSize = Math.max(1, pageSize);
49
		pageNo = Math.max(1, pageNo);
50
		if (list.isEmpty()) {
51
			ret.setData(list);
52
			ret.setPageNo(pageNo);
53
			ret.setPageSize(1);
54
		} else if (pageNo == 1) {
55
			ret.setPageNo(pageNo);
56
			ret.setPageSize(pageSize);
57
			ret.setData(list.subList(0,Math.min(list.size(), pageSize)));
58
		} else {
59
			int tps = list.size() / pageSize;
60
			if (list.size() % pageSize != 0) {
61
				++tps;
62
			}
63
			if (pageNo > tps) {
64
				pageNo = tps;
65
			}
66
			ret.setPageNo(pageNo);
67
			ret.setPageSize(pageSize);
68
			int begin = pageNo * pageSize - pageNo;
69
			ret.setData(list.subList(begin,Math.min(list.size(), begin + pageSize)));
70
		}
71
		return ret;
72
	}
73
74
	public static void main(String[] args) {
75
		new PageQueryResult<String>().setData(Collections.<String> emptyList());
76
40 77
	}
41 78
}