1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 静态方法调用注入对象(springMvc)

静态方法调用注入对象(springMvc)

时间:2021-05-30 05:37:43

相关推荐

静态方法调用注入对象(springMvc)

独角兽企业重金招聘Python工程师标准>>>

java代码:

package com.mon.web;import java.util.List;import javax.annotation.PostConstruct;import mons.collections.CollectionUtils;import org.apache.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import com.its.mmo.MmoException;import com.its.mmo.Status;import com.mon.dao.WechatAccountDao;import com.mon.model.WechatAccount;@Controllerpublic class WechatAccountCtrl{private final static Logger logger=Logger.getLogger(WechatAccountCtrl.class);@Autowiredprivate WechatAccountDao wechatAccountDao; //注入对象private static WechatAccountCtrl wechatAccountCtrl;@PostConstruct //利用PostConstruct注解初始化赋值public void init(){wechatAccountCtrl=this;wechatAccountCtrl.wechatAccountDao=this.wechatAccountDao;}/*** 根据品牌id查询微信账户* @param brandId* @throws MmoException*/public static WechatAccount getWechatAccount(String brandId) throws MmoException {List<WechatAccount> accounts = null;try {accounts = wechatAccountCtrl.wechatAccountDao.queryWxInfo(brandId);} catch (Exception e) {logger.error("根据品牌id查询微信账户错误", e);throw new MmoException(Status.SERVICE_FAIL, "根据品牌id查询微信账户错误", e);}if (CollectionUtils.isEmpty(accounts)) {logger.info("该品牌不存在微信账户");throw new MmoException(Status.SERVICE_FAIL, "该品牌不存在微信账户");}return accounts.get(0);}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。