从数据库取出一个 Count函数 统计的值
在代码中要转成Integer类型的时候
String sqlCount = "SELECT count(1) "+ "FROM (t_mch_XXX s LEFT JOIN t_bank_XXX b ON s.`CODE` = b.CUST_ID) "+ "LEFT JOIN t_cls_XXX t ON s.`CODE` = t.MCH_CODE "+ "WHERE t.SETTLE_DATE>? AND t.SETTLE_DATE<? AND s.CLS_MODE = 'INDIRECT' AND t.AMOUNT_SETTLE > 0";
Query queryCount = addQueryParams(getEntityManager().createNativeQuery( sqlCount ), new Object[]{search.getSettleDate().getStart(),search.getSettleDate().getEnd()});
BigDecimal decimal = (BigDecimal) queryCount .getResultList().get(0); 项目跑起来,点查询的时候就报下面的错:
java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.math.BigDecimal
也试过这种方法 BigDecimal decimal = (BigDecimal)queryCount.getSingleResult() == null ? 0:queryCount.getSingleResult() ; 还是报同样的错 。
最后 ,使用绝招 ,不是不能转么,那就直接用 BigInteger
Object count = queryCount.getSingleResult() == null ? 0:queryCount.getSingleResult(); BigInteger i= (BigInteger)count;
这样就行了 。