我是靠谱客的博主 要减肥身影,这篇文章主要介绍Springboot之 CommandLineRunner的使用,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cn.huasheng.micro.basic.runner; import cn.huasheng.micro.basic.constant.RedisConstant; import cn.huasheng.micro.basic.dto.sys.AppDTO; import cn.huasheng.micro.basic.po.sys.AppPO; import cn.huasheng.micro.basic.service.sys.AppService; import cn.huasheng.micro.common.utils.RedisUtil; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import java.util.List; @Component @Order(value = 5)//延后执行 @Slf4j //注意:CommandLineRunner会在ApplicationRunner之后执行 public class MicroCommandLineRunner implements CommandLineRunner {//继承ApplicationRunner也可以 @Autowired private AppService appService; public void run(String... args) throws Exception { log.warn("执行MicroCommandLineRunner...."); //以下是业务操作 QueryWrapper<AppPO> wrapper=new QueryWrapper<>(); List<AppPO> appPOList= appService.getBaseMapper().selectList(wrapper); if(CollUtil.isNotEmpty(appPOList)){ appPOList.forEach(i->{ RedisUtil.set(RedisConstant.RESOURCE_APP_INFO+i.getId(),appDTO); }); } } }

最后

以上就是要减肥身影最近收集整理的关于Springboot之 CommandLineRunner的使用的全部内容,更多相关Springboot之内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(103)

评论列表共有 0 条评论

立即
投稿
返回
顶部