zoukankan      html  css  js  c++  java
  • springboot接口:CommandLineRunner

    springBoot接口:CommandLineRunner

    一、作用:

    在使用SpringBoot构建项目时,我们通常有一些预先数据的加载。那么SpringBoot提供了一个简单的方式来实现–CommandLineRunner。

    二、用法:

    CommandLineRunner是一个接口,我们需要时,只需实现该接口就行。如果存在多个加载的数据,我们也可以使用@Order注解来排序。

    @Component
    @Order(value = 2)
    public class MyStartupRunner1 implements CommandLineRunner{
    @Override
    public void run(String... strings) throws Exception {
        System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作 MyStartupRunner1 order 2 <<<<<<<<<<<<<");
        }
    }
    
    @Component
    @Order(value = 1)
    public class MyStartupRunner2 implements CommandLineRunner {
    @Override
    public void run(String... strings) throws Exception {
        System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作 MyStartupRunner2 order 1 <<<<<<<<<<<<<");
        }
    }
    

    三、展示:

  • 相关阅读:
    边框
    文本样式
    框架
    表格
    列表
    标签
    常用类--包装类
    常见类 --Object
    日志
    异常
  • 原文地址:https://www.cnblogs.com/xujie09/p/11261542.html
Copyright © 2011-2022 走看看