函数接口
- CommandLineRunner.run(String…)接受原始的参数:String… 按照空格+trim切分为数组(带 “-”) 得到 [–name=john,github.com]
- ApplicationRunner.run(ApplicationArguments)则对原始参数做了封装:ApplicationArguments 可以接收key/value形式的参数,可通过 getOptionValues(“name”) 得到john,也可以通过getSourceArgs() 像 CommandLineRunner 一样获取源参数数组。
/**
* 入参: {@code --name=john github.com}
*
* <p>{@link CommandLineRunner#run(String...)}接受原始的参数:{@code String...} 按照空格+trim切分为数组(带 "-") 得到
* {@code [--name=john,github.com]}
*
* <p>{@link ApplicationRunner#run(ApplicationArguments)}则对原始参数做了封装:{@code ApplicationArguments}
* 可以接收key/value形式的参数,可通过 {@code getOptionValues("name")} 得到john,也可以通过getSourceArgs() 像 {@code
* CommandLineRunner} 一样获取源参数数组。
*
* <blockquote>
*
* <pre>{@code
* @Bean
* public CommandLineRunner commandLineRunner() {
* return args -> {
* log.info(driverService.pickUp());
* };
* }
* }</pre>
*
* </blockquote>
*
* @return lambda 表达式
*/
@Bean
public ApplicationRunner runner() {
return args -> {
log.info(driverService.pickUp("zhang san"));
};
}