引用IGenericBaseCommonDao类中的方法报错
使用IGenericBaseCommonDao类中的findByQueryString方法报空指针异常,使用代码如下:错误提示如下:
没人遇到过吗? 小白问题,你这个测试类都不在spring容器里面管理,怎么能这么写 但是,我这样写也还是不行啊!
Controller类:
service类:
@Service("mtOrderinfoService")
public class MtOrderinfoServiceImpl extends CommonServiceImpl implements MtOrderinfoServiceI {
@Transactional(readOnly=true)
public Integer getOrderCountNum(String hql) {
return this.commonDao.executeHql(hql);
}
}
OrderNumFillRule 类:
public class OrderNumFillRule implements IFillRuleHandler{
private static final Logger logger = LoggerFactory.getLogger(OrderNumFillRule.class);
@Autowired
private MtOrderinfoServiceI mtOrderinfoService;
//订单号生成计数器
private Integer orderNumCount = 0;
// 锁对象,可以为任意对象
private static Object lockObj = "lockerOrder";
private Integer weishu;
@Override
public Object execute(String paramJson) {
String prefix="";
if(paramJson!=null && !"".equals(paramJson)){
JSONObject jsonObject = JSONObject.fromObject(paramJson);
Object obj = jsonObject.get("prefix");
if(obj!=null)prefix=obj.toString();
}
String orderNum = prefix+this.createPendingOrder();
return orderNum;
}
/**
*
* @Description:订单号生成
* @param user 获取当前用户的所在城市信息
* @return finOrderNum 生成的订单号
*/
public String createPendingOrder() {
synchronized (lockObj) {
// 取系统当前时间作为订单号变量前半部分
String yearMonth = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).substring(2, 6);
String qz = ResourceUtil.getSessionUser().getCityCode() + yearMonth;
orderNumCount = this.getMaxPendingOrder(qz);// 获得订单号数量
if (orderNumCount !=0) {
weishu=orderNumCount;
weishu+=1;
}else
weishu=1;
String strWeiShu=weishu.toString();
for(int i = strWeiShu.length();i<=2;i++){
if(i<2) {
strWeiShu = "00" + strWeiShu;
}else
strWeiShu="0"+strWeiShu;
}
String finOrderNum=qz+strWeiShu;
orderNumCount++;
logger.info("ordernum:"+finOrderNum);
return finOrderNum;
}
}
/**
*
* @Description:获取数据库订单号的最大数量
* @param qz 查询条件
* @return 订单号的最大数量
*/
public Integer getMaxPendingOrder(String qz){
System.out.println("qz:"+qz);
String hql="select count(mt.order_num) from mt_orderinfo mt where 1=1 and "
+ "mt.order_num like '"+ qz + "%'order by mt.order_num desc";
Integer countNum=mtOrderinfoService.getOrderCountNum(hql);
System.out.println("size:"+countNum);
return countNum;
}
还是一样的报空指针:
还是在引用方法的时候写错啦?
页:
[1]