通过实测:mybatis 中的sql语句int类型 java接管的几种状况。

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

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

<select id="getTest" resultType="int">    select id from ting_cmdb_physical_equipment where id=2897;</select>

显示后果,

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接管

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>

运算后果:

java能够用int接管

3.2 id做运算

<select id="getTest" resultType="map">    select id-1 as id     from ting_cmdb_physical_equipment where id=2897;</select>

运算后果

java能够用long接管


3.3 id做聚合运算

<select id="getTest" resultType="map">    select sum(id) as id     from ting_cmdb_physical_equipment where id=2897;</select>

运算后果:

java能够用BigDecimal接管

总结

类型\int值没做运算做了运算做了聚合运算
intintintint
Map<String,Object>intlongBigDecimal
List<String,Object>intlongBigDecimal

为什么会呈现BigDecimal类型呢,
通过下面的测试:
能够得出

  1. 用的是Map<String,Object>,List<Map<String,Object>>接管,
  2. sql语句中int类型的值做了聚合运算

满足上述两个条件。
java中去取value的值就会变成 BigDecimal 类型