当前位置: 首页 > news >正文

温州哪里做网站设计wordpress免签约支付

温州哪里做网站设计,wordpress免签约支付,现在网站给源码,营销型网站设计注意AOP到底是啥 前言面向切面编程到底是啥意思那么要怎么实现面向切面编程呢#xff1f;成果 前言 回忆起来#xff0c;第一次听到这三字母是博主在上大二的时候#xff0c;那时候看的一脸懵逼#xff0c;现在马上研二了才想起来回顾下。 只记得当时面向对象编程还没整明白成果 前言 回忆起来第一次听到这三字母是博主在上大二的时候那时候看的一脸懵逼现在马上研二了才想起来回顾下。 只记得当时面向对象编程还没整明白这一下子又来个面向切面编程这直接给整懵了。。。。 面向对象相信大家都很了解了那咱们接下来看看什么是面向切面编程。 面向切面编程到底是啥意思 咱不整哪些官方话术了整点通俗的。 想象以下这样的一个场景你接手了一个人员管理系统这个项目并没有做任何的权限管理并且大部分功能已经完成这时候甲方突然来了个新需求我现在希望你加上对人员管理的权限即部门经理只能管理其部门的人员不能管理其他部门的人员。 这时候你可能想到要不加个安全框架但很快你就放弃了因为这种需要给权限的接口实在是太多了总不能一个个根据用户权限限制管理权限这么去改吧。 这时候aop的作用就出现了 那可以怎么做呢 我们通常会将包含接口的Controller都放在一个package中这时候我们就在想我们可不可以在职工id传递给接口之前对传递的职工id操作一下呢 即前端传递过来之后我们在对这些id再进行一次审核将没有权限管理的职工id删掉可以不 很幸运可以 我们可以认为客户端到调用接口这之间存在一个面在这个面上我们可以处理将要传递给接口的id参数进行处理将那些没有权限操作的id直接删除。这个面就可以认为是切面面向切面编程就是这样。 这里只是一个例子切面不仅存在这种情况中对象和对象之间方法和方法之间等等之间都可以认为是一个切面。 那么要怎么实现面向切面编程呢 这里我们用注解的方式实现 首先就是我们怎么监视这个面呢 先看下接口 package com.xiaow.springsecuriydemo.controller;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.xiaow.springsecuriydemo.entity.Person; import com.xiaow.springsecuriydemo.service.PersonService; import com.xiaow.springsecuriydemo.vo.Result; import io.jsonwebtoken.lang.Collections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.util.Collection; import java.util.List;/*** p* 前端控制器* /p** author xiaow* since 2023-09-01*/ RestController RequestMapping(/person) public class PersonController {AutowiredPersonService personService;GetMapping(getPersons)public Result getPersons(int adminid, int[] personids) {LambdaQueryWrapperPerson personLambdaQueryWrapper new LambdaQueryWrapper();List list1 Collections.arrayToList(personids);personLambdaQueryWrapper.in(Person::getId, list1);ListPerson list personService.list(personLambdaQueryWrapper);return Result.succ(list);}} 这里的mplus操作就交给大家去写了。 来了解下怎么写Aspect Before(value execution(* com.xiaow.springsecuriydemo.controller.*.*(..)))Before也就是在接口执行前我们对其进行操作com.xiaow.springsecuriydemo.controller就是我们存放controller的包后面的第一个*代表任意一个Controller第二个* 就是任意的方法 其意义就是在com.xiaow.springsecuriydemo.controller下的所有接口执行前做一步处理那么处理什么呢 当然是处理传递的员工id就是把那些无权限处理的id替代掉这里我们使用-1来代替因为id为-1不会指向任何员工信息。 看下完整的代码 package com.xiaow.springsecuriydemo.aop.advice;import com.xiaow.springsecuriydemo.aop.annotation.ArgsAnnotation; import com.xiaow.springsecuriydemo.aop.annotation.ArraysAnnotation; import com.xiaow.springsecuriydemo.entity.Admin; import com.xiaow.springsecuriydemo.entity.Person; import com.xiaow.springsecuriydemo.service.AdminService; import com.xiaow.springsecuriydemo.service.PersonService; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component;import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.util.Arrays; import java.util.List;Aspect Component public class PersonAdvice {AutowiredAdminService adminService;AutowiredPersonService personService;// 在进入接口之前执行Before(value execution(* com.xiaow.springsecuriydemo.controller.*.*(..)))public void before(JoinPoint joinPoint) throws IllegalAccessException, NoSuchFieldException {final Signature signature joinPoint.getSignature();MethodSignature methodSignature (MethodSignature) signature;// 获取参数的名字final String[] names methodSignature.getParameterNames();// 获取参数的值final Object[] args joinPoint.getArgs();int admin_index -1;int personid_index -1;// 获取到adminid和personids的下标位置for (int i 0; i names.length; i) {if (names[i].equals(adminid)) {admin_index i;}if (names[i].equals(personids)) {personid_index i;}}Integer adminid (Integer) args[admin_index];int [] personid (int[]) args[personid_index];Admin byId adminService.getById(adminid);if (byId ! null) {Integer deptid byId.getDeptid();ListPerson byDeptIdAndPersonids personService.getByDeptIdAndPersonids(deptid, personid);int[] personids (int[]) args[personid_index];for (Integer i 0; i personids.length; i) {boolean flag false;for (Person byDeptIdAndPersonid : byDeptIdAndPersonids) {if (personids[i] byDeptIdAndPersonid.getId())flag true;} // 若不在有权限的id中则直接设置为-1if (!flag)Array.setInt(personid, i, -1);}}}// 在接口执行完毕后执行After(value execution(* com.xiaow.springsecuriydemo.controller.*.*(..)))public void after() {System.out.println(after);}}成果 就这样我们在不修改原有的接口的情况下实现了权限控制如下图
http://www.zqtcl.cn/news/568141/

相关文章:

  • 网站公司查询js代码网站大全
  • 湘潭网站建设价格最新新闻热点事件100字
  • 音乐网站程序源码wordpress模板中文版
  • 网站建设计划表wordpress主题 大
  • 在手机制作网站书店网站建设技术风险
  • 爱站网域名查询wordpress自定义标题关键词描述
  • 西安学校网站建设报价建盏
  • 网页 网站 区别东莞手机app开发
  • 空压机网站开发公司广州海珠区有什么好玩的景点
  • 什么网站可以做期货企业解决方案服务协议
  • 西安汽车网站制作手机软件制作网站平台
  • 微信的微网站介绍自己的家乡遵义网站建设
  • 爱站seo东莞网站建设要注意什么
  • 惠州网站建设 英语6wordpress 表格提交
  • 做网站15年多少钱一度电
  • 北京网站域名快速备案外贸网站优化价格
  • 做网站 工资高吗免费建站的站点网站
  • 个人做营利性质网站会怎么样qq邮箱官方网站
  • 网站怎么做等级保护产品展示小程序
  • 奉贤网站建设专家高端自适应网站设计
  • 网站正在建设中 动态徐州网站建设方案咨询
  • 广东世纪达建设集团有限公司官方网站专业电商网站开发
  • 抚顺建设网站自适应网站建设推荐
  • 做网站的大公司手机页面
  • 网站建设的公司实习做什么系统设计
  • 兰州网站设计哪个平台好外贸网站定制公司哪家好
  • 做网站需要先买域名吗在线音乐网站开发数据库
  • 深圳优化网站搬家网站模板
  • 网站建设做的人多吗门户网站制作建设
  • 哪个网站可以做logo怀柔网页公司制作