mysql 的 int 类型,刨析返回类型为 BigDicemal 类型的奇怪现象
java 可以用 int 接收。
1.2 如果 resultType=“int”, id 做运算,
<select id="getTest" resultType="int">
select id-1 as id
from ting_cmdb_physical_equipment where id=2897;
</select>
显示结果:
java 可以用 int 接收
1.3 id 做聚合运算
<select id="getTest" resultType="int">
select sum(id) as id
from ting_cmdb_physical_equipment where id=2897;
</select>
运算结果:
java 可以用 int 接收
![mysql 的 int 类型,返回为 BigDicemal 的奇怪现象](https://im
g-blog.csdnimg.cn/img_convert/93d918c24c18bbf1038d0afefe4e73fe.png)
2.用 resultType=“map”(返回类型用 Map<String,Object>)
================================================================================================================
2.1 id 没做运算
<select id="getTest" resultType="map">
select id from ting_cmdb_physical_equipment where id=2897;
</select>
运算结果:
java 可以用 int 接收
2.2 id 做运算
<select id="getTest" resultType="map">
select id-1 as id
from ting_cmdb_physical_equipment where id=2897;
</select>
运算结果:
java 要用 long 类型接收
2.3 id 做聚合函数运算
<select id="getTest" resultType="map">
select sum(id) as id
from ting_cmdb_physical_equipment where id=2897;
</select>
运算结果:
java 用 BigDecimal 接收
3.resultType=“map” (返回类型用 list<Map<String,Object>>)
======================================================================================================================
3.1 id 没做运算
<select id="getTest" resultType="map">
select id as id
from ting_cmdb_physical_equipment where id=2897;
</select>
评论