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 += "  <a href=" + url + "&page=1>首页</a>";
if (this.isHasPrevious())
this.description += "  <a href=" + url + "&page="
+ (this.currentPage - 1) + ">上一页</a>";
else
this.description += "  上一页";
if (this.isHasNext())
this.description += "  <a href=" + url + "&page="
+ (this.currentPage + 1) + ">下一页</a>";
else
this.description += "  下一页";
this.description += "  <a href=" + url + "&page="
+ this.totalPages + ">尾页</a>";
this.description += "  跳转至";
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) + "')\"> " + (j + 1) + " </a>";
} else {

this.description += "<a href='#' style='background:#B1369C'' onclick=\"return go_page('"
+ (j + 1)
+ "')\"><font color='#FFFFFF' style='background:#B1369C'> "
+ (j + 1) + " </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;
}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值