注册

java枚举映射 空值转换为0的问题

哈哈 2024/05/17 492 1

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】: 8
【操作系统】:linux
【CPU】:
【问题描述】*:在代码中使用mybatis-plus映射时,里面的枚举值应该是空的,但被赋值了。查源码过程中发现short字段是空的话,会转换成0。这不符合逻辑吧?

具体代码呈现如下。

实体类:

public class SafeCheckItem { /** * 主键id */ private Long id; /** * 整改结果 */ private RectificationResult rectificationResult; }

mybatis里的sql就是单纯读取的sql,但是业务需求原因,是一对多映射的

<resultMap id="SafeCheckItemMap" type="com.zjplan.gas.cylinder.vo.customerVO.SafeCheckItemVO"> <result column="id" property="id"/> <result column="rectification_result" property="rectificationResult"/> </resultMap> <resultMap id="SafeCheckRecordMap" type="com.zjplan.gas.cylinder.vo.customerVO.SafeCheckRecordVO"> <result column="id" property="id"/> <collection property="items" columnPrefix="i_" resultMap="SafeCheckItemMap"/> </resultMap> <select id="selectSafeCheckRecordByCode" resultMap="SafeCheckRecordMap"> SELECT sc.id, sci.id as i_safe_check_code, sci.rectification_result as i_rectification_result FROM cylinder.safe_check AS sc LEFT JOIN cylinder.safe_check_item AS sci ON sc.id = sci.id WHERE sc."delete" = 0 AND sc.safe_check_code = #{safeCode} </select>

数据库里safe_check_item表为空,safe_check表有值,本来想得到的结果是safe_check表有值而附带的子列表为空。pg可以实现,dm实现不了。

查源码过程:枚举的映射是基于mybatis-plus的映射函数MybatisEnumTypeHandler,用到了re.getObject()。得到的object value就不一样。

枚举Bug.png

继续往下查,看了PgResultSet.java和DmdbResultSet.java,发现了区别。
image.png
image.png

这个算是bug吧?

回答 0
暂无回答
扫一扫
联系客服