MyBatis 对于 decimal 类型的处理技巧如下:
通过 resultMap 映射查询结果集中的 decimal 类型字段:<resultMap id="resultMap" type="YourClass"> <result column="your_column" property="yourProperty" jdbcType="DECIMAL"/></resultMap>在 SQL 语句中使用 CAST 函数将 decimal 类型字段转换成其他类型:<select id="selectById" resultMap="resultMap"> SELECT CAST(your_decimal_column AS DECIMAL(10,2)) AS your_property FROM your_table WHERE id = #{id}</select>在实体类中定义 BigDecimal 类型的属性来存储 decimal 类型字段的值:private BigDecimal yourProperty;通过以上技巧,你可以很方便地处理 MyBatis 中的 decimal 类型字段。


