mysql的 int 类型,刨析返回类型为BigDicemal 类型的奇怪现象

您所在的位置:网站首页 mybatis查询总数返回值类型 mysql的 int 类型,刨析返回类型为BigDicemal 类型的奇怪现象

mysql的 int 类型,刨析返回类型为BigDicemal 类型的奇怪现象

2024-03-11 05:27| 来源: 网络整理| 查看: 265

经过实测:mybatis 中的sql语句int类型 java接收的几种情况。

1.用resultType=“int” (返回类型用int)

mysql的int类型,返回为BigDicemal的奇怪现象

1.1 如果 resultType=“int”, id 没做运算,

select id from ting_cmdb_physical_equipment where id=2897;

显示结果,

java可以用 int 接收。

mysql的int类型,返回为BigDicemal的奇怪现象

1.2 如果 resultType=“int”, id 做运算,

select id-1 as id from ting_cmdb_physical_equipment where id=2897;

显示结果:

java可以用int接收

mysql的int类型,返回为BigDicemal的奇怪现象

1.3 id 做聚合运算

select sum(id) as id from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用int接收

mysql的int类型,返回为BigDicemal的奇怪现象

2.用resultType=“map”(返回类型用Map)

mysql的int类型,返回为BigDicemal的奇怪现象

2.1 id没做运算

select id from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用int 接收

mysql的int类型,返回为BigDicemal的奇怪现象

2.2 id做运算

select id-1 as id from ting_cmdb_physical_equipment where id=2897;

运算结果:

java要用long类型接收

mysql的int类型,返回为BigDicemal的奇怪现象

2.3 id做聚合函数运算

select sum(id) as id from ting_cmdb_physical_equipment where id=2897;

运算结果:

java用BigDecimal接收

mysql的int类型,返回为BigDicemal的奇怪现象

3.resultType=“map” (返回类型用list)

mysql的int类型,返回为BigDicemal的奇怪现象

3.1 id没做运算

select id as id from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用int接收

mysql的int类型,返回为BigDicemal的奇怪现象

3.2 id做运算

select id-1 as id from ting_cmdb_physical_equipment where id=2897;

运算结果

java可以用long接收

mysql的int类型,返回为BigDicemal的奇怪现象

3.3 id做聚合运算

select sum(id) as id from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用BigDecimal接收

mysql的int类型,返回为BigDicemal的奇怪现象

总结

类型\int值没做运算做了运算做了聚合运算intintintintMapintlongBigDecimalListintlongBigDecimal

为什么会出现BigDecimal类型呢,

经过上面的测试:

可以得出

用的是 Map ,List接收,sql语句中int类型的值做了 聚合运算 ,

满足上述两个条件。

java中去取value的值就会变成 BigDecimal 类型



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3