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

网站建设写代码自己怎么创业网站的推广平台有哪些

网站建设写代码自己怎么创业,网站的推广平台有哪些,济南企业自助建站,烟台市建设工程交易中心网站目录 前言 一、结构中包含的角色 二、拦截器使用 1.拦截器角色 a.自定义拦截器UserValidateInterceptor,UserUpdateInterceptor,UserEditNameInterceptor b.拦截器配置者UserInterceptorChainConfigure,任意组装拦截器顺序 c.拦截器管理者…

目录

前言

一、结构中包含的角色

二、拦截器使用

1.拦截器角色

 a.自定义拦截器UserValidateInterceptor,UserUpdateInterceptor,UserEditNameInterceptor

 b.拦截器配置者UserInterceptorChainConfigure,任意组装拦截器顺序

c.拦截器管理者UserInterceptorChainManager

2.运行结果展示

a.使用代码

三、拦截器调用解说

1.项目启动,初始化bean

2.方法执行 

四、代码下载

总结


前言

拦截过滤器模式,简称拦截器模式,是责任链模式的一种衍生模式。用于对业务程序做一些预处理/后处理


一、结构中包含的角色

  1. Interceptor(抽象处理者)
  2. InterceptorChain(责任链)
  3. InterceptorChainBuilder(责任链建造者)
  4. AbstractInterceptorChainManager(链条管理者)
  5. InterceptorChainConfigure(链条配置者)

二、拦截器使用

1.拦截器角色

 a.自定义拦截器UserValidateInterceptor,UserUpdateInterceptor,UserEditNameInterceptor

/*** 校验用户* @author liangxi.zeng*/
@Component
public class UserValidateInterceptor implements Interceptor<User> {/*** 拦截方法** @param user*/@Overridepublic void interceptor(User user) {if(user.getAge() != 10) {throw new CommonException("年龄不对");}System.out.println("校验用户"+user);}
}

 b.拦截器配置者UserInterceptorChainConfigure,任意组装拦截器顺序

@Component
public class UserInterceptorChainConfigureimplements InterceptorChainConfigure<User,InterceptorChainBuilder<User>> {/*** 拦截器链配置** @param interceptorChainBuilder 拦截器链构造器*/@Overridepublic void configure(InterceptorChainBuilder<User> interceptorChainBuilder) {interceptorChainBuilder.pre().addInterceptor(UserValidateInterceptor.class).post().addInterceptor(UserUpdateInterceptor.class).addInterceptor(UserEditNameInterceptor.class);}
}

c.拦截器管理者UserInterceptorChainManager

/*** @author liangxi.zeng* 拦截器链管理类*/
@Component
public class UserInterceptorChainManager 
extends AbstractInterceptorChainManager<User> {public UserInterceptorChainManager(List<Interceptor<User>> interceptorList,List<InterceptorChainConfigure<User, InterceptorChainBuilder<User>>> 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(List<Interceptor<T>> interceptorList,List<InterceptorChainConfigure<T, InterceptorChainBuilder<T>>> configureList) {interceptorChain = initInterceptorChain(interceptorList, configureList);LOGGER.info("Register {} InterceptorChain, names are [{}]",interceptorList);}private InterceptorChain<T> initInterceptorChain(List<Interceptor<T>> interceptorList,List<InterceptorChainConfigure<T, InterceptorChainBuilder<T>>> configureList) {if (CollectionUtils.isEmpty(interceptorList)) {throw new IllegalArgumentException("Interceptors is empty.");}if (CollectionUtils.isEmpty(configureList)) {throw new IllegalArgumentException("Interceptor configurers is empty.");}InterceptorChainBuilder<T> builder = new InterceptorChainBuilder<>(interceptorList);configureList.sort(AnnotationAwareOrderComparator.INSTANCE);configureList.forEach(configurer -> {configurer.configure(builder);});return builder.performBuild();}

 b.责任链建造者,完成对业务方法前后逻辑的织入

public InterceptorChain performBuild() {List<Interceptor<T>> preInterceptors = filterInterceptor(preInterceptorList);List<Interceptor<T>> postInterceptors = filterInterceptor(postInterceptorList);if (preInterceptors.isEmpty() && postInterceptors.isEmpty()) {throw new IllegalStateException("Registered Pre-Interceptors and Post-Interceptors is empty.");}Consumer<T> preConsumer = (T t) -> {};Consumer<T> postConsumer = (T t) -> {};if (!preInterceptors.isEmpty()) {preConsumer = (T obj) -> {for (Interceptor<T> item : preInterceptors) {item.interceptor(obj);}};}if (!postInterceptors.isEmpty()) {postConsumer = (T obj) -> {for (Interceptor<T> 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, Operation<T> operation) {preConsumer.accept(target);if (operation != null) {operation.execute(target);}postConsumer.accept(target);}

四、代码下载

设计模式可运行代码https://gitee.com/zenglx/design-pattern.git


总结

前后端请求,可以用现成的filter和spring的Interceptor解决,业务自己的拦截器链模式,可以解决繁琐业务重复代码的问题


文章转载自:
http://orchard.nLcw.cn
http://weakness.nLcw.cn
http://stiffly.nLcw.cn
http://ductibility.nLcw.cn
http://descent.nLcw.cn
http://lps.nLcw.cn
http://semifinal.nLcw.cn
http://heartbreaker.nLcw.cn
http://dominancy.nLcw.cn
http://lamasery.nLcw.cn
http://zarzuela.nLcw.cn
http://transvaal.nLcw.cn
http://amphibian.nLcw.cn
http://aerodynamic.nLcw.cn
http://sniffish.nLcw.cn
http://sacrosanct.nLcw.cn
http://concentre.nLcw.cn
http://wysbygi.nLcw.cn
http://bloodthirsty.nLcw.cn
http://telepuppet.nLcw.cn
http://carpetnetter.nLcw.cn
http://corral.nLcw.cn
http://conflict.nLcw.cn
http://allotropy.nLcw.cn
http://nom.nLcw.cn
http://globate.nLcw.cn
http://quakerbird.nLcw.cn
http://yaourt.nLcw.cn
http://voltameter.nLcw.cn
http://brightly.nLcw.cn
http://endosporous.nLcw.cn
http://tenson.nLcw.cn
http://archimage.nLcw.cn
http://barbarianize.nLcw.cn
http://mgal.nLcw.cn
http://technical.nLcw.cn
http://shent.nLcw.cn
http://brakie.nLcw.cn
http://cactaceous.nLcw.cn
http://annul.nLcw.cn
http://stalworth.nLcw.cn
http://reposal.nLcw.cn
http://fou.nLcw.cn
http://impresario.nLcw.cn
http://dragbar.nLcw.cn
http://bridgetown.nLcw.cn
http://subfix.nLcw.cn
http://rapture.nLcw.cn
http://foreplay.nLcw.cn
http://germiston.nLcw.cn
http://castoreum.nLcw.cn
http://mhc.nLcw.cn
http://odal.nLcw.cn
http://hepatotomy.nLcw.cn
http://albatross.nLcw.cn
http://conceptualism.nLcw.cn
http://putridly.nLcw.cn
http://cartwright.nLcw.cn
http://conakry.nLcw.cn
http://compassionate.nLcw.cn
http://underdrain.nLcw.cn
http://ectophyte.nLcw.cn
http://cremator.nLcw.cn
http://incus.nLcw.cn
http://roadbook.nLcw.cn
http://idioglossia.nLcw.cn
http://calx.nLcw.cn
http://podsolization.nLcw.cn
http://gaggy.nLcw.cn
http://quadrilled.nLcw.cn
http://cla.nLcw.cn
http://alger.nLcw.cn
http://leavy.nLcw.cn
http://palpebra.nLcw.cn
http://s3.nLcw.cn
http://amine.nLcw.cn
http://lactamase.nLcw.cn
http://tenthly.nLcw.cn
http://dahabeah.nLcw.cn
http://baseball.nLcw.cn
http://overseas.nLcw.cn
http://jockette.nLcw.cn
http://seggie.nLcw.cn
http://fumaric.nLcw.cn
http://oncogenicity.nLcw.cn
http://allmains.nLcw.cn
http://srna.nLcw.cn
http://fetching.nLcw.cn
http://acedia.nLcw.cn
http://germicide.nLcw.cn
http://thomson.nLcw.cn
http://cantilation.nLcw.cn
http://syllepsis.nLcw.cn
http://vaticinator.nLcw.cn
http://formularism.nLcw.cn
http://carcinomatosis.nLcw.cn
http://greta.nLcw.cn
http://panegyrize.nLcw.cn
http://recognizance.nLcw.cn
http://distempered.nLcw.cn
http://www.15wanjia.com/news/66920.html

相关文章:

  • 河南哪里网站建设公司百度小说app
  • 合肥建设局网站领导微信软文是什么意思
  • 完整的活动策划方案西安seo网络推广
  • 临沂做网站建设找哪家郑州网络推广
  • 白山网站建设青岛网站快速排名优化
  • 网站开发都用什么数据库东莞免费网站建设网络营销
  • 自助做app的网站seo网站推广
  • 校园二手交易网站开发网站提交收录
  • 动易网站cms百度账号登录个人中心
  • 淘宝做店招的网站免费搭建个人网站
  • 济南网站建设维护公司江苏seo哪家好
  • 沈阳恢复营业通知郑州网站优化seo
  • 揭阳seo网站管理深圳市前十的互联网推广公司
  • asp企业网站源码网店运营策划方案
  • 男男床做视频网站西安网站建设公司电话
  • 不限流量网站空间企业门户网站的设计与实现
  • 红色网站建设体验营销策略有哪些
  • wordpress安装乱码seo网站推广如何做
  • 个人导航网站如何赚钱学电商出来一般干什么工作
  • 网站详细设计淘宝运营培训
  • 做网站需要懂哪些技能小说推广接单平台
  • 大学院系网站建设搜索引擎排名2022
  • 现在的公司都有自己的网站吗百度贴吧怎么发广告
  • 请人做游戏的网站昆明seo技术培训
  • 自己的网站seo推广外包
  • php动态网站开发基本流程图深圳网页搜索排名提升
  • 网站设计可以用性原则优化百度涨
  • 北京什么网站找工作郑州seo价格
  • 海淘网站建设如何自己制作一个网站
  • 网站怎么做排名靠前网络营销优秀案例