springAOP(Aspect)权限访问页面

1、XML进行配置切面

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><bean id="jurisdictionAdvice" class="com.wbg.sums.web.aspect.jurisdictionAdvice"/><aop:config><!--定义切面--><aop:aspect id="authAspect" ref="jurisdictionAdvice"><!-- 定义切入点--><aop:pointcut id="jurisdictionPointCut" expression="
                 execution(* com.wbg.sums.web.*.deleteByPrimaryKey(..)) orexecution(* com.wbg.sums.web.*.updateByPrimaryKey(..))"/><!--方法环绕--><aop:around method="readOnly" pointcut-ref="jurisdictionPointCut"/></aop:aspect></aop:config>
</beans>

View Code

2、定义切面和切点

package com.wbg.sums.web.aspect;import com.wbg.sums.dto.Result;
import com.wbg.sums.entity.Jurisdiction;
import com.wbg.sums.service.JurisdictionService;
import com.wbg.sums.service.MemberInformationService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpSession;@Component
@Aspect
@EnableAspectJAutoProxy
public class jurisdictionAdvice {@AutowiredHttpSession httpSession;//用户
    @Autowiredprivate MemberInformationService memberInformationService;//权限
    @Autowiredprivate JurisdictionService jurisdictionService;public Result readOnly(ProceedingJoinPoint pj){//方法String method = pj.getSignature().getName();System.out.println(method);//获取用户String user = (String) httpSession.getAttribute("user");//模拟updateByPrimaryKeyif(method.equals("updateByPrimaryKey")){user="100010003";}else {user="100010004";}//查询根据用户查询权限int jid = memberInformationService.selectJid(user);//获取权限
        System.out.println(jid);Jurisdiction jurisdiction = jurisdictionService.selectByPrimaryKey(jid);System.out.println(jurisdiction);//如果是最高管理if(jid == 1){try {return (Result) pj.proceed();} catch (Throwable throwable) {throwable.printStackTrace();}}//如果是中级管理 并方法是修改else if( jid == 2 && method.equals("updateByPrimaryKey")){try {return (Result) pj.proceed();} catch (Throwable throwable) {throwable.printStackTrace();}}return new Result().error("权限不足");}
}

View Code

3、controller层

Result代码:

package com.wbg.sums.dto;public class Result {//    1203错误编码
//       1224正确编码,有返回数据
//       1028正确编码,无返回数据
//       1222 正确编码 无错误  用于判断删除成功或者失败/*** 当修改添加删除 成功的时候,统一使用successMessage方法   编码为1028  否则就是没有成功**///状态码int code;//数据
    Object data;//消息提示
    String message;public Result() {}public Result(String message) {this.code=1222;this.message = message;}//数量int count;public int getCount() {return count;}public void setCount(int count) {this.count = count;}public Result(int code, String message, Object data, int count) {this.code = code;this.data = data;this.message = message;this.count = count;}public Result(int code, String message) {this.code = code;this.message = message;}public int getCode() {return code;}public void setCode(int code) {this.code = code;}public Object getData() {return data;}public void setData(Object data) {this.data = data;}public String getMessage() {return message;}public void setMessage(String message) {this.message = message;}/*** successMessage* 正常返回,携带消息* code:1028** @param message 消息*                data:null*                count:0* @return*/public static Result successMessage(String message) {return new Result(1028, message);}/*** success* 成功方法 带数据返回* code:1224** @param data    数据* @param count     总数* @return*/public static Result success(Object data, int count) {return new Result(1224, "success", data, count);}/*** success* 成功方法 带数据返回* code:1224* message: success** @param data 数据*             count :0* @return*/public static Result success(Object data) {return new Result(1224, "success", data, 0);}/*** error* code:203* data:null* count:0** @param message 错误信息* @return*/public static Result error(String message) {return new Result(1203, message);}}

View Code

测试:

posted @ 2018-12-20 11:54 韦邦杠 阅读(...) 评论(...) 编辑 收藏

springAOP(Aspect)权限访问页面相关推荐

  1. asp.net core根据用户权限控制页面元素的显示

    asp.net core根据用户权限控制页面元素的显示 Intro 在 web 应用中我们经常需要根据用户的不同允许用户访问不同的资源,显示不同的内容,之前做了一个 AccessControlHelp ...

  2. [SharePoint]如何防止从代码跳到“拒绝访问”页面

    在代码中执行没有权限的操作时,SharePoint平台会抛出"拒绝访问(access denied)"异常,并将用户重定向到_layouts/AccessDenied.aspx页面 ...

  3. Windows 无法访问指定设备,路径或文件。你可能没有合适的权限访问这个项目。

    Windows 无法访问指定设备,路径或文件.你可能没有合适的权限访问这个项目. 0. 背景 出现这个问题的背景如下: 电脑安装有金山毒霸 win10 系统 打开部分.exe文件情况报上述错 1. 报 ...

  4. AOP 关于面向切面编程实现权限访问功能

    什么是面向切面 AOP技术利用一种称为"横切"的技术,剖解开封装对象的内部,将影响多个类的公共行为封装到一个可重用的模块中,并将其命名为Aspect切面.所谓的切面,简单来说就是与 ...

  5. 基于Python, Selenium, Phantomjs无头浏览器访问页面

    引言: 在自动化测试以及爬虫领域,无头浏览器的应用场景非常广泛,本文将梳理其中的若干概念和思路,并基于代码示例其中的若干使用技巧. 1. 无头浏览器 通常大家在在打开网页的工具就是浏览器,通过界面上输 ...

  6. java cpu过高排查_CPU使用率过高,访问页面的速度越来越慢?今天我教你解决

    tomcat要运行依赖于JDK,tomcat服务器的CPU使用率过高,大多都是因为部署的web程序的问题. 一.现象描述 在一次线上环境,前台访问页面的速度越来越慢,从浏览器F12中看到发出的请求都是 ...

  7. linux访问网页元素,Linux_DOM和JAVASCRIPT访问页面上的元素,访问方法:getElementById() - phpStudy...

    DOM和JAVASCRIPT访问页面上的元素 访问方法: getElementById():返回拥用传递给该方法的指定id的第一个对象的引用. getElementsByName():返回拥用传递该方 ...

  8. maven WEB项目启动没问题访问页面就报错:org.apache.jasper.JasperException: Unable to compile class for JSP

    idea 通过maven插件创建一个WEB项目通过内嵌Tomcat加载项目,启动没问题,一访问页面就报错提示无法将jsp编译为class文件: HTTP Status 500 - type Excep ...

  9. Eclipse中新建jsp文件访问页面时乱码问题

    新建.jsp文件,charset和pageEncoding默认是ISO-8859-1,这样的话访问页面时会出现乱码,解决办法:将charset和pageEncoding改为UTF-8(或者GBK/GB ...

  10. php判断访客语言,php实现获取及设置用户访问页面语言类

    本文实例讲述了php实现获取及设置用户访问页面语言类,分享给大家供大家参考.具体分析如下: 该实例User Language Class 获取/设置用户访问的页面语言,如果用户没有设置访问语言,则读取 ...

最新文章

  1. 〖Java〗Eclispe安装和使用viplugin
  2. php和python和java-Java、Python与PHP的虚拟机异同
  3. 利用fstream进行文件拷贝测试
  4. 用户请求队列化_爬虫架构消息队列应用场景及ActiveMQ、RabbitMQ、RocketMQKafka
  5. (1)Deep Learning之感知器
  6. 博客园是否提供trackback的rss
  7. [高光谱] GitHub开源项目Hyperspectral-Classification的解析
  8. [Zju 2112][逆序对统计] 线段树(四) {线段树扩展}
  9. Android Palette吸色原理及源码解析
  10. Java开发QQ机器人
  11. 高校校园网建设方案【含网络拓扑图+拓扑结构图+配置命令】(详细版)
  12. “风味人间”与计算机程序设计艺术《禅与计算机程序设计艺术》
  13. STAT0023 STATISTICS FOR PRACTICAL COMPUTING
  14. access订单明细表怎么做_如何制作材料明细表...doc
  15. 笔记本电脑外放没声音,或外放有声音/插耳机没声音———Realtek High Definition Audio Driver安装
  16. SVG进阶-SMIL动画
  17. java的声音处理方法
  18. springboot-rabbitmq-reply 消息直接回复模式
  19. 如何让你pycharm用起来更舒服,看起来更美观
  20. 算法设计与分析练习题

热门文章

  1. Tf-idf推导及理解
  2. python怎么求中位数_Python求两个有序数组的中位数的几种方法
  3. python gui控件案例_python基础教程python GUI库图形界面开发之PyQt5布局控件QHBoxLayout详细使用方法与实例...
  4. ubuntu更新源 apt-get install Unable to locate package
  5. php float转int 元转分
  6. 浅析bin,lib,src的区别
  7. 常见微型计算机外部输入设备,微型计算机常用外部设备
  8. mybatis mysql 注解_Mybatis注解的使用
  9. ShutdownHook- Java 优雅停机解决方案
  10. Intellij IDEA|phpstorm 相关收藏