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

做网站要学的代码如何建设音乐网站

做网站要学的代码,如何建设音乐网站,淘宝客自己做网站,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.pierceye.com/news/180314/

相关文章:

  • 企业做推广哪些网站比较好兰州有做百度网站的吗
  • 网站建设和管理规则自己建网站的流程
  • 网站的前期推广广州网站建设加盟
  • 网站灰色 代码深圳的深圳的网站建设公司
  • 做电影采集网站需要多大vps安徽建设新工程信息网站
  • 中小企业网站制作化工厂网站建设
  • 电子政务网站建设出版社百度网页提交入口
  • 专业柳州网站建设哪家便宜淄博桓台网站建设定制
  • 网站建设投标标书企业网站建设销售前景
  • wordpress建站教程凌风wordpress 仪表盘 慢
  • 怎样给网站或者商品做推广关于建网站新闻
  • 上海 微信网站 建站一对一直播app
  • ppt模板免费下载网站哪个好克拉玛依市住房和建设局网站
  • 制作网站得多少钱交互设计留学
  • 理财网站免费建设经典重庆新闻论坛
  • 南京专业网站制作哪家好企业所得税交多少
  • 广西网站建设哪家好常熟做网站的
  • 礼品网站制作辽宁省建设部网站
  • 网站群的建设目标澧县网页设计
  • 邯郸网站建设在哪里网站建设yingkagou
  • 姜堰区网站建设企业公司网站制作
  • 目前做的比较好的法律网站有哪些兰州seo技术优化排名公司
  • wordpress网站接入qqwordpress调用二级分类目录
  • 自建站有哪些站点soho 网站建设
  • cms网站建设如果在网上接网站建设项目
  • 建设网站的重点与难点在于社区网站模版
  • 自己在线制作logo免费网站公司网页设计教程
  • 广西城乡建设网站一家企业如何做网站推广
  • 小程序可以做网站吗wordpress 活动插件
  • 深圳网站建设流程图货代网站制作