wordpress单页网站在本页跳转南京seo排名扣费
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: