mal是什么类型对应的java类型是什么,【Java】mysql的 int 类型,刨析返回类型为BigDicemal 类型的奇怪现象...

用的是Map,List>接收,

sql语句中int类型的值做了聚合运算,

满足上述两个条件。

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

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

实测案例:

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

c95f3599f6cd253af27b7220a418f2a9.png

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

select id from ting_cmdb_physical_equipment where id=2897;

显示结果,

java可以用 int 接收。

dcc31068ba828fd3738af1badc3e428c.png

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

select id-1 as id

from ting_cmdb_physical_equipment where id=2897;

显示结果:

java可以用int接收

e9e5502ec27cd2ca80ad660dcbca552b.png

1.3 id 做聚合运算

select sum(id) as id

from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用int接收

4a8c14a935cfe9cdc2cf27be15e67062.png

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

e4912dcef18b8d33d6d28cd2b6cca92c.png

2.1 id没做运算

select id from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用int 接收

58645cb60de0d6f7ba81c901a21c9843.png

2.2 id做运算

select id-1 as id

from ting_cmdb_physical_equipment where id=2897;

运算结果:

java要用long类型接收

4635d5ee94f84fc6b37fb205adfaec2f.png

2.3 id做聚合函数运算

select sum(id) as id

from ting_cmdb_physical_equipment where id=2897;

运算结果:

java用BigDecimal接收

8f8cbcebfaa36d81980811e57efa9fc1.png

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

d7dd00265069a00f9d0167ead1cb14ec.png

3.1 id没做运算

select id as id

from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用int接收

6ec4943db75bb83c4879c35cbdf50861.png

3.2 id做运算

select id-1 as id

from ting_cmdb_physical_equipment where id=2897;

运算结果

java可以用long接收

f8e0e1e34088f02573b84d2acb66447d.png

3.3 id做聚合运算

select sum(id) as id

from ting_cmdb_physical_equipment where id=2897;

运算结果:

java可以用BigDecimal接收

216c97b9ba185abc563c51dbd9397589.png

总结

类型\int值

没做运算

做了运算

做了聚合运算

int

int

int

int

Map

int

long

BigDecimal

List

int

long

BigDecimal

为什么会出现BigDecimal类型呢,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值