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

建设自有网站需要什么静态网站公用头部如何调用标题

建设自有网站需要什么,静态网站公用头部如何调用标题,重庆市建设工程人力资源网,中信建设证券网站目录 前言 一、结构中包含的角色 二、拦截器使用 1.拦截器角色 a.自定义拦截器UserValidateInterceptor#xff0c;UserUpdateInterceptor#xff0c;UserEditNameInterceptor b.拦截器配置者UserInterceptorChainConfigure#xff0c;任意组装拦截器顺序 c.拦截器管理者… 目录 前言 一、结构中包含的角色 二、拦截器使用 1.拦截器角色 a.自定义拦截器UserValidateInterceptorUserUpdateInterceptorUserEditNameInterceptor b.拦截器配置者UserInterceptorChainConfigure任意组装拦截器顺序 c.拦截器管理者UserInterceptorChainManager 2.运行结果展示 a.使用代码 三、拦截器调用解说 1.项目启动初始化bean 2.方法执行  四、代码下载 总结 前言 拦截过滤器模式,简称拦截器模式是责任链模式的一种衍生模式。用于对业务程序做一些预处理/后处理 一、结构中包含的角色 Interceptor抽象处理者InterceptorChain责任链InterceptorChainBuilder责任链建造者AbstractInterceptorChainManager链条管理者InterceptorChainConfigure链条配置者)二、拦截器使用 1.拦截器角色 a.自定义拦截器UserValidateInterceptorUserUpdateInterceptorUserEditNameInterceptor /*** 校验用户* author liangxi.zeng*/ Component public class UserValidateInterceptor implements InterceptorUser {/*** 拦截方法** param user*/Overridepublic void interceptor(User user) {if(user.getAge() ! 10) {throw new CommonException(年龄不对);}System.out.println(校验用户user);} } b.拦截器配置者UserInterceptorChainConfigure任意组装拦截器顺序 Component public class UserInterceptorChainConfigureimplements InterceptorChainConfigureUser,InterceptorChainBuilderUser {/*** 拦截器链配置** param interceptorChainBuilder 拦截器链构造器*/Overridepublic void configure(InterceptorChainBuilderUser interceptorChainBuilder) {interceptorChainBuilder.pre().addInterceptor(UserValidateInterceptor.class).post().addInterceptor(UserUpdateInterceptor.class).addInterceptor(UserEditNameInterceptor.class);} } c.拦截器管理者UserInterceptorChainManager /*** author liangxi.zeng* 拦截器链管理类*/ Component public class UserInterceptorChainManager extends AbstractInterceptorChainManagerUser {public UserInterceptorChainManager(ListInterceptorUser interceptorList,ListInterceptorChainConfigureUser, InterceptorChainBuilderUser configureList) {super(interceptorList, configureList);} }2.运行结果展示 a.使用代码 /*** author liangxi.zeng*/ RestController RequestMapping(/demo) public class DemoController {Autowiredprivate UserInterceptorChainManager userInterceptorChainManager;Autowiredprivate UserService userService;RequestMapping(/user)public String user() {User user new User();user.setId(111);user.setName(liangxi);user.setAge(10);userInterceptorChainManager.doInterceptor(user,(u) - {// 内部创建用户userService.save(user);});return success;}}三、拦截器调用解说 1.项目启动初始化bean a.初始化责任链管理者UserInterceptorChainManager调用父类AbstractInterceptorChainManager方法initInterceptorChain通过责任链建造者初始化责任链 public AbstractInterceptorChainManager(ListInterceptorT interceptorList,ListInterceptorChainConfigureT, InterceptorChainBuilderT configureList) {interceptorChain initInterceptorChain(interceptorList, configureList);LOGGER.info(Register {} InterceptorChain, names are [{}],interceptorList);}private InterceptorChainT initInterceptorChain(ListInterceptorT interceptorList,ListInterceptorChainConfigureT, InterceptorChainBuilderT configureList) {if (CollectionUtils.isEmpty(interceptorList)) {throw new IllegalArgumentException(Interceptors is empty.);}if (CollectionUtils.isEmpty(configureList)) {throw new IllegalArgumentException(Interceptor configurers is empty.);}InterceptorChainBuilderT builder new InterceptorChainBuilder(interceptorList);configureList.sort(AnnotationAwareOrderComparator.INSTANCE);configureList.forEach(configurer - {configurer.configure(builder);});return builder.performBuild();} b.责任链建造者完成对业务方法前后逻辑的织入 public InterceptorChain performBuild() {ListInterceptorT preInterceptors filterInterceptor(preInterceptorList);ListInterceptorT postInterceptors filterInterceptor(postInterceptorList);if (preInterceptors.isEmpty() postInterceptors.isEmpty()) {throw new IllegalStateException(Registered Pre-Interceptors and Post-Interceptors is empty.);}ConsumerT preConsumer (T t) - {};ConsumerT postConsumer (T t) - {};if (!preInterceptors.isEmpty()) {preConsumer (T obj) - {for (InterceptorT item : preInterceptors) {item.interceptor(obj);}};}if (!postInterceptors.isEmpty()) {postConsumer (T obj) - {for (InterceptorT item : postInterceptors) {item.interceptor(obj);}};}return new InterceptorChain(preConsumer,postConsumer);} 2.方法执行  a.从userInterceptorChainManager.doInterceptor 到 interceptorChain.doExecute(target, operation);下面代码完成代码逻辑 /*** 拦截器调用入口将核心操作封装成 Consumer 对象传入。** param target The target to handle.* param operation The core operation to intercept.*/public final void doExecute(T target, OperationT operation) {preConsumer.accept(target);if (operation ! null) {operation.execute(target);}postConsumer.accept(target);} 四、代码下载 设计模式可运行代码https://gitee.com/zenglx/design-pattern.git 总结 前后端请求可以用现成的filter和spring的Interceptor解决业务自己的拦截器链模式可以解决繁琐业务重复代码的问题
http://www.hkea.cn/news/14507025/

相关文章:

  • 衡水提供网站制作公司哪家好网站的创新点
  • 长沙做网站好的公司有哪些企业网络营销方案策划书
  • 深圳网站建设厂家wordpress自动发货如何设置
  • 城市文明建设网站公司文化墙设计
  • 制作网站建设策划方案怎么找合适的网站开发
  • 运城 网站制作台州网站设计外包
  • 防城港网站制作南昌网站建设在哪里
  • 大渡口网站建设wordpress极验验证注册
  • 中小型网站建设新闻网站做直播吗
  • 企业产品网站源码山东东营市房价
  • 盐城企业网站制作购物网站建设价格一览表
  • 网站备案查询验证码错误自媒体横行还有做网站
  • 做网站建设出路在哪里wordpress分类目录排序
  • 建设网站有什么网站受雇去建设网站类网站
  • 优秀的定制网站建设公司没有网站可以做京东联盟吗
  • 重庆建网站价格表58同城的网站建设
  • 医生可以自己做网站吗现在流行的网站开发
  • asp.net 网站开发的技术优势wordpress 模板文件
  • 创欧科技 网站建设如何做直接打开网站的二维码
  • 网站制作技巧017网站购买域名之后再怎么做
  • wordpress国外主题网站模板书画网站 建站
  • 建设网站所需要的技术备案平台新增网站
  • 公司如何建设一个网站镇江网站公司
  • 网站的站外推广手段如果给公司做网站
  • 网站建设财务上怎么处理网站开发前端后端
  • 龙岗个性化网站建设价格低网站建设网站制作哪个好
  • 长沙网站定制公司可以用自己的电脑做网站主机
  • 数据库 搭建 网站沈阳快速排名优化
  • wordpress建站需要多大内存租服务器多少钱
  • 两个网站合并建设实施方案小程序开发平台网站推荐