简体   繁体   English

java.math.BigInteger 不能强制转换为 java.lang.Integer,ZAC5C24B64B4BAC83

[英]java.math.BigInteger cannot be cast to java.lang.Integer , sql Dialect is not configured

I'm using spring boot 1.5, I want to get alerts grouped by their status (four status).thereby I'm using a native query in the repository.我正在使用 spring 启动 1.5,我想获取按状态(四个状态)分组的警报。因此我在存储库中使用本机查询。 when I run that query it's giving me the result.当我运行该查询时,它会给我结果。 but it doesnt work with the service.但它不适用于该服务。 the result I've got when I run with the console: https://drive.google.com/open?id=1eson3nEHAIEr-jdEgkC1-tw2acRsW728使用控制台运行时得到的结果: https://drive.google.com/open?id=1eson3nEHAIer-jdEgkC1-tw2acRsW728

the service is:服务是:

  @Override
public List<DashboardAlertVO> countingStatus() {
    return alertRepository.countStatus()
            .stream()
            .map(o -> new DashboardAlertVO(AlertStatus.fromValue((String) o[0]),
                    ((Integer) o[1])))
            .collect(Collectors.toList());
}

so I'm getting this error:所以我收到了这个错误:

"message": "java.math.BigInteger cannot be cast to java.lang.Integer",

I don't know what's matter really with this code.我不知道这段代码有什么问题。 Please help.请帮忙。 Thank you a lot.十分感谢。

We can not type cast BigInteger to Integer by simply using integer keyword.我们不能通过简单地使用 integer 关键字将 BigInteger 类型转换为 Integer。 Instead you should use the inbuilt method intValue() of BigInteger class to get the integer part.相反,您应该使用 BigInteger class 的内置方法 intValue() 来获取 integer 部分。

@Override
public List<DashboardAlertVO> countingStatus() {
    return alertRepository.countStatus()
        .stream()
        .map(o -> new DashboardAlertVO(AlertStatus.fromValue((String) o[0]),
                (o[1].intValue())))
        .collect(Collectors.toList());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.Integer不能强制转换为java.math.BigInteger - java.lang.Integer cannot be cast to java.math.BigInteger java.math.BigInteger 不能转换为 java.lang.Integer - java.math.BigInteger cannot be cast to java.lang.Integer 如何解决 java.math.BigInteger 无法转换为 java.lang.Integer? - How to work around java.math.BigInteger cannot be cast to java.lang.Integer? 如何解决 java.math.BigInteger 无法转换为 java.lang.Integer - How to work around java.math.BigInteger cannot be cast to java.lang.Integer Playorm java.lang.Integer无法强制转换为java.math.BigInteger - Playorm java.lang.Integer cannot be cast to java.math.BigInteger java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.math.BigInteger HTTP状态500 - java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigInteger HTTP Status 500 java.math.BigInteger 无法转换为 java.lang.Long - java.math.BigInteger cannot be cast to java.lang.Long java.lang.Long无法强制转换为java.math.BigInteger - java.lang.Long cannot be cast to java.math.BigInteger java.lang.ClassCastException:java.math.BigInteger无法强制转换为java.lang.Long - java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long java.math.BigInteger无法强制转换为java.math.BigDecimal - java.math.BigInteger cannot be cast to java.math.BigDecimal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM