当前使用版本(必填,否则不予处理)
3.5.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
Entity示例:
@TableName(value = "table_name", autoResultMap = true)
public class TableName extends BaseEntity {
private static final long serialVersionUID = 1L;
@TableField(typeHandler = FastjsonTypeHandler.class)
private List<String> openResult;
}
xml示例:
<select id="get" resultType="xxx.xxx.entity.TableName">
SELECT a.*
FROM table_namea,
(SELECT id FROM table_nameWHERE is_open = true ORDER BY id DESC LIMIT 1) b
WHERE a.id = b.id
</select>
如上所示,get()方法的typeHandler将不会生效,需定义为:
<resultMap id="testResultMap" autoMapping="true" type="tw.game.ft.entity.FtRecordOpen">
<result column="open_result" jdbcType="VARCHAR" property="openResult" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler" />
</resultMap>
<select id="get" resultMap="testResultMap">
SELECT a.*
FROM table_namea,
(SELECT id FROM table_nameWHERE is_open = true ORDER BY id DESC LIMIT 1) b
WHERE a.id = b.id
</select>
@TableField(typeHandler = FastjsonTypeHandler.class)生效范围:
- serviceImpl.xxx()内置默认实现
- baseMapper.xxx()内置默认实现
你好,如果@TableField(typeHandler = FastjsonTypeHandler.class)不支持在xml文件中定义的resultType="xxx.xxx.entity.TableName",可以考虑在代码注释中或官方文档中进行说明,避免后续开发者踩坑,谢谢!
如果这是一个bug,需求是可以支持的,我可以为此提供一个PR来支持此场景。
Comment From: miemieYaho
resultType != resultMap
Comment From: yl-yue
其实我的需求很简单,就是在xml文件中定义sql时,我需要重新定义result,还是可以直接指向对应的entity,这样就不需要重复定义了,因为映射关系(转换关系)我已经在实体类声明过了。
想确认下,是否必须在xml中重新声明一遍。 @miemieYaho
- 在实体中需要声明一遍,用于默认
crud实现 - 在
xml中重新声明一遍,用于自己编写的sql
请问是这样么,还是有更好的方式,无需重复在xml中定义
Comment From: miemieYaho
准从mybatis的规则下是这样的
Comment From: yl-yue
遵从mybatis的规则下是这样的
请问有方案实现么,能否给个思路我去实现,算是个mybatis-plus的增强特性
Comment From: miemieYaho
Comment From: z-xiaohua
<select id="get" resultType="xxx.xxx.entity.TableName" resultMap="mybatis-plus_TableName">
</select>
能简单解决这个问题
Comment From: yuanchenyangGithub
nvocation of init method failed; nested exception is java.lang.IllegalArgumentException: Result Maps collection does not contain value for
<select id="get" resultType="xxx.xxx.entity.TableName" resultMap="mybatis-plus_TableName"> </select>能简单解决这个问题