spring aop


package aop;

import javax.servlet.http.HttpSession;

import org.aspectj.lang.ProceedingJoinPoint;

public class PowerAspect {

	// 切面
	public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
		long time = System.currentTimeMillis();         
		
		Object retVal = pjp.proceed();
		time = System.currentTimeMillis() - time;
//		Object args[]=pjp.getArgs();
		//pjp.get
//	    HttpSession session=(HttpSession)args[0];
//	    
//		for(int i=0;i<args.length;i++){
//			
//			//System.out.println("---------->"+args[i].getClass()+"--------->"+args[i].);
//			
//		}
		System.out.println(pjp.getTarget().getClass().getName()+"---->"+pjp.getSignature().getName()+"---->"+"process time--->: " + time + " ms");
		//System.out.println("----->"+retVal);
		//return "操作失败,权限不够!";
		return retVal;
	}

}



	<!-- spring aop -->
	<aop:config>

		<aop:aspect id="aspect" ref="powerAspect">
			<!--定义切入点 -->
			<aop:pointcut id="servicePointcut"
				expression="execution(* serviceimp.*.*(..))" />
			<!-- 定义通知 -->
			<aop:around pointcut-ref="servicePointcut"
				method="doAround" />
		</aop:aspect>

	</aop:config>

	<!-- 定义一个切面 -->
	<bean id="powerAspect" class="aop.PowerAspect"></bean>



---------------------------------------------------------------------------




package util;

public class Page {
	int totalRowsAmount; // 总行数

	int pageSize = 10; // 每页行数

	int currentPage = 1; // 当前页码

	int nextPage;

	int previousPage;

	int totalPages; // 总页数

	boolean hasNext; // 是否有下一页

	boolean hasPrevious; // 是否有前一页

	String description;

	int pageStartRow;

	int pageEndRow;

	int p_start;

	int p_end;

	public Page() {

	}

	public Page(int totalRows, int pageSize) {
		// this.totalRowsAmount=totalRows;
		setPageSize(pageSize);
		setTotalRowsAmount(totalRows);

	}

	public void setTotalRowsAmount(int i) {
		this.totalRowsAmount = i;
		if (this.totalRowsAmount % this.pageSize == 0)
			totalPages = this.totalRowsAmount / this.pageSize;
		else
			totalPages = this.totalRowsAmount / this.pageSize + 1;
	}

	public void setCurrentPage(int i, String url) {
		if (i < 1)
			currentPage = 1;
		else if (i > totalPages)
			currentPage = totalPages;
		else
			currentPage = i;

		nextPage = currentPage + 1;

		previousPage = currentPage - 1;

		// // 计算当前页开始行和结束行
		if (currentPage * pageSize <= totalRowsAmount) {
			pageEndRow = currentPage * pageSize;
			pageStartRow = pageEndRow - pageSize + 1;
			if (pageStartRow <= 0)
				pageStartRow = 0;

		} else {
			pageEndRow = totalRowsAmount;
			pageStartRow = pageSize * (totalPages - 1) + 1;
		}

		// 是否存在前页和后页

		if (currentPage >= totalPages)
			hasNext = false;
		else
			hasNext = true;
		if (currentPage <= 1)
			hasPrevious = false;
		else
			hasPrevious = true;

		p_start = currentPage - 5; // 10条

		if (p_start <= 0)
			p_start = 1;

		p_end = p_start + 10;

		if (p_end > totalPages)
			p_end = totalPages;

		p_start = p_end - 10;

		if (p_start <= 0)
			p_start = 1;

		this.description = "共有" + this.getTotalRowsAmount() + "条记录,显示"
				+ this.getPageStartRow() + "到" + this.getPageEndRow();
		this.description += "&nbsp;&nbsp;<a href=" + url + "&page=1>首页</a>";
		if (this.isHasPrevious())
			this.description += "&nbsp;&nbsp;<a href=" + url + "&page="
					+ (this.currentPage - 1) + ">上一页</a>";
		else
			this.description += "&nbsp;&nbsp;上一页";
		if (this.isHasNext())
			this.description += "&nbsp;&nbsp;<a href=" + url + "&page="
					+ (this.currentPage + 1) + ">下一页</a>";
		else
			this.description += "&nbsp;&nbsp;下一页";
		this.description += "&nbsp;&nbsp;<a href=" + url + "&page="
				+ this.totalPages + ">尾页</a>";
		this.description += "&nbsp;&nbsp;跳转至";
		this.description += "<select id='page' onchange='go()'>";
		for (int k = 1; k <= this.totalPages; k++) {
			if (k == this.currentPage)
				this.description += "<option value='" + k
						+ "' selected='selected'>" + k + "</option>";
			else
				this.description += "<option value='" + k + "'>" + k
						+ "</option>";
		}
		this.description += "</select>";
		this.description += "页";
		// System.out.println(this.description());
	}

	public void setCurrentPage01(int i) {
		if (i < 1)
			currentPage = 1;
		else if (i > totalPages)
			currentPage = totalPages;
		else
			currentPage = i;

		p_start = currentPage - 5; // 10条

		if (p_start < 0)
			p_start = 0;

		p_end = p_start + 10;

		if (p_end > totalPages)
			p_end = totalPages;

		p_start = p_end - 10;

		if (p_start < 0)
			p_start = 0;

		this.description += "<a href='#' onclick=\"return go_page('"
				+ (currentPage - 1) + "')\">上一页</a>";

		for (int j = p_start; j < p_end; j++) {

			if ((j + 1) != currentPage) {
				this.description += "<a href='#' onclick=\"return go_page('"
						+ (j + 1) + "')\">&nbsp;" + (j + 1) + "&nbsp;</a>";
			} else {

				this.description += "<a href='#' style='background:#B1369C'' onclick=\"return go_page('"
						+ (j + 1)
						+ "')\"><font color='#FFFFFF' style='background:#B1369C'>&nbsp;"
						+ (j + 1) + "&nbsp;</font></a>";
			}
		}

		this.description += "<a href='#' onclick=\"return go_page('"
				+ (currentPage + 1) + "')\">下一页</a>";

	}

	public int getCurrentPage() {
		return currentPage;
	}

	public boolean isHasNext() {
		return hasNext;
	}

	public boolean isHasPrevious() {
		return hasPrevious;
	}

	public int getNextPage() {
		return nextPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getPreviousPage() {
		return previousPage;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public int getTotalRowsAmount() {
		return totalRowsAmount;
	}

	public void setHasNext(boolean b) {
		hasNext = b;
	}

	public void setHasPrevious(boolean b) {
		hasPrevious = b;
	}

	public void setNextPage(int i) {
		nextPage = i;
	}

	public void setPageSize(int i) {
		pageSize = i;
	}

	public void setPreviousPage(int i) {
		previousPage = i;
	}

	public void setTotalPages(int i) {
		totalPages = i;
	}

	public int getPageEndRow() {
		return pageEndRow;
	}

	public int getPageStartRow() {
		return pageStartRow;
	}

	public String getDescription() {
		return description;
	}

	public int getP_end() {
		return p_end;
	}

	public void setP_end(int p_end) {
		this.p_end = p_end;
	}

	public int getP_start() {
		return p_start;
	}

	public void setP_start(int p_start) {
		this.p_start = p_start;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setPageEndRow(int pageEndRow) {
		this.pageEndRow = pageEndRow;
	}

	public void setPageStartRow(int pageStartRow) {
		this.pageStartRow = pageStartRow;
	}

}


你可能感兴趣的:(spring,AOP,servlet,J#)