jiapeng 8 gadi atpakaļ
vecāks
revīzija
1d8a620db7

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

26
import org.jfw.apt.web.handlers.ChangeResultHandler;
26
import org.jfw.apt.web.handlers.ChangeResultHandler;
27
import org.jfw.apt.web.handlers.CharacterEncodingHandler;
27
import org.jfw.apt.web.handlers.CharacterEncodingHandler;
28
import org.jfw.apt.web.handlers.ExecuteHandler;
28
import org.jfw.apt.web.handlers.ExecuteHandler;
29
import org.jfw.apt.web.handlers.InvalidSessionHandler;
29
import org.jfw.apt.web.handlers.JdbcConnectionHandler;
30
import org.jfw.apt.web.handlers.JdbcConnectionHandler;
30
import org.jfw.apt.web.handlers.LastScriptHandler;
31
import org.jfw.apt.web.handlers.LastScriptHandler;
31
import org.jfw.apt.web.handlers.LoginUserHandler;
32
import org.jfw.apt.web.handlers.LoginUserHandler;
363
		supportedClass.add(ExecuteHandler.class);
364
		supportedClass.add(ExecuteHandler.class);
364
		supportedClass.add(SetSessionHandler.class);
365
		supportedClass.add(SetSessionHandler.class);
365
		supportedClass.add(SetCookieHandler.class);
366
		supportedClass.add(SetCookieHandler.class);
367
		supportedClass.add(InvalidSessionHandler.class);
366
		supportedClass.add(ChangeResultHandler.class);
368
		supportedClass.add(ChangeResultHandler.class);
367
		supportedClass.add(LastScriptHandler.class);
369
		supportedClass.add(LastScriptHandler.class);
368
		supportedClass.add(ResultToNullHandler.class);
370
		supportedClass.add(ResultToNullHandler.class);

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

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

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
	private int total;
7
	private int total;
8
	private int pageNo = 1;
8
	private int pageNo = 1;
9
	private int pageSize;
9
	private int pageSize;
10
	
10
11
	public int getTotal() {
11
	public int getTotal() {
12
		return total;
12
		return total;
13
	}
13
	}
14
14
	public void setTotal(int total) {
15
	public void setTotal(int total) {
15
		this.total = total;
16
		this.total = total;
16
	}
17
	}
18
17
	public int getPageNo() {
19
	public int getPageNo() {
18
		return pageNo;
20
		return pageNo;
19
	}
21
	}
22
20
	public void setPageNo(int pageNo) {
23
	public void setPageNo(int pageNo) {
21
		this.pageNo = pageNo;
24
		this.pageNo = pageNo;
22
	}
25
	}
26
23
	public int getPageSize() {
27
	public int getPageSize() {
24
		return pageSize;
28
		return pageSize;
25
	}
29
	}
30
26
	public void setPageSize(int pageSize) {
31
	public void setPageSize(int pageSize) {
27
		this.pageSize = pageSize;
32
		this.pageSize = pageSize;
28
	}
33
	}
34
29
	public List<T> getData() {
35
	public List<T> getData() {
30
		return data;
36
		return data;
31
	}
37
	}
38
32
	public void setData(List<T> data) {
39
	public void setData(List<T> data) {
33
		this.data = data;
40
		this.data = data;
34
	}
41
	}
42
35
	private List<T> data;
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
}