tx

wangcx

栖迟於一丘,则天下不易其乐
64,346
java 静态方法中依赖注入调用 Service 层 java 静态方法中依赖注入调用 Service 层
实现如下
@Component  // 交由spring管理
public class CommonUtil {
 
    @Autowired  // 注入
    private TRUserRoleService trUserRoleService;
 
    // 声明对象
    public static CommonUtil commonUtil;
 
    @PostConstruct // 初始化
    public void init(){
        commonUtil = this;
        commonUtil.trUserRoleService = this.trUserRoleService;
    }
 
    public static void getUserRoleList(TRUser user) {
        // 调用
        List<TRUserRole> userRoleList = commonUtil.trUserRoleService.findByUser(new TRUser(user.getId()));
    }
}
0 条评论

评论已关闭 >_<

随机一言

:D 获取中...

文章目录

最新评论

随机文章

网站升级 1250 浏览 - 2022/05/31
MySQL 的 now() 函数 1412 浏览 - 2023/02/07
对 List 进行手动分页 969 浏览 - 2022/11/09
XML 中大于号和小于号的处理 1205 浏览 - 2022/11/30
网站搬迁到野草云香港服务器 1175 浏览 - 2024/05/18