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

ComnandLineRunner接口, ApplcationRunner接口

ComnandLineRunner接口, ApplcationRunner接口

介绍:

        这两个接口都有一个run方法,执行时间在容器对象创建好后,自动执行run ( )方法。 创建容器的同时会创建容器中的对象,同时会把容器中的对象的属性赋上值

举例: 
@SpringBootApplication
public class Application implements CommandLineRunner {@Resourceprivate HelloService helloService;public static void main(String[] args){System.out.println("准备创建容器对象1111111");SpringApplication.run(Application.class,args);System.out.println("容器对象创建好之后33333");}@Overridepublic void run(String... args) throws Exception {String str = helloService.hello("李四");System.out.println("调用容器中的对象:"+str);//可以自定义操作,如读取文件、数据库等System.out.println("在容器对象创建好后,执行run方法222222");}
}
public interface HelloService {String hello(String name);
}
@Service
public class HelloServiceImpl implements HelloService {@Overridepublic String hello(String name) {return "您好:"+name;}
}
执行结果: 

 

拦截器 

拦截器是SpringMVC中一种对象,能拦截器对Controller的请求。
拦截器框架中有系统的拦截器,还可以自定义拦截器。实现对请求预先处理。

拦截器的使用步骤:

 1、创建类实现Handlerlnterceptor接口:根据需要重写其中的preHandle()、postHandle()、afterCompletion()
 2、自定义类来实现WebMvcConfigurer接口,在配置类中声明拦截器对象以及要拦截的请求路径

 

http://localhost:8081/mydev/user/account

 

http://localhost:8081/mydev/user/login:

http://www.lryc.cn/news/467006.html

相关文章:

  • Swift用于将String拆分为数组的components与split的区别
  • docker之redis安装(项目部署准备)
  • 使用Maven前的简单准备
  • Java | Leetcode Java题解之第494题目标和
  • 阅读笔记 Contemporary strategy analysis Chapter 13
  • Python GUI 编程:tkinter 初学者入门指南——复选框
  • 使用vscode导入库失败解决方法
  • 无线网卡知识的学习-- mac80211主要代码流程
  • 关于k8s集群高可用性的探究
  • 保姆级Pinpoint(APM)实战教程
  • 使用SpringBoot自定义注解+AOP+redisson锁来实现防接口幂等性重复提交
  • k8s和ipvs、lvs、ipvsadm,iptables,底层梳理,具体是如何实现的
  • 三、归一化与标准化
  • B2105 矩阵乘法
  • centos之下的mysql8的安装
  • 计算机导论
  • 力扣209-长度最小的子数组-滑动窗口思想
  • Xilinx 7系列FPGA PCI Express IP核简介
  • 红包雨html
  • js 基础补充3
  • Invalid bean definition with name ‘employeeMapper‘ defined in file
  • 悦享驾驶,乐在旅途,首选江铃集团新能源易至EV3青春版
  • 测试WIFI和以太网的TCP带宽、UDP带宽和丢包率、延时
  • redis 第155节答疑 源码分析Hash类型ziplist结构和zlentry实体解析
  • IDE使用技巧与插件推荐
  • 1020接口测试面试题随记
  • Zotero7最新(2024)翻译问题——配置 百度API翻译
  • python程序设计员—练习笔记
  • 1.DBeaver连接hive数据库
  • CODESYS随机动态图案验证码制作详细案例(三)