稷然如此

  • 首页
  • 文章分类
    • AI
    • Android
    • Java
    • Shell
    • Vue
    • C#
    • Python
    • 数据库
    • 组件
    • 其他
    • Game
  • 常用命令
    • Docker
    • Git
    • Linux
  • 操作系统
    • CentOS
    • Ubuntu
    • Windows
    • Kylin
  • 工具
    • IntelliJ IDEA
    • Visual Studio Code
稷然如此
不积跬步,无以至千里
  1. 首页
  2. 文章分类
  3. Java
  4. 正文

MyBatis-Plus 使用 typeHandler 自定义查询没有生效问题

2025年4月27日 125点热度 0人点赞
实体类:
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "test", autoResultMap = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Test {
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> ids;
}
Mapper Xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.TestRepository">
	<select id="getByPeisNoInStation" resultType="com.example.Test">
		select
			ids
		from test
	</select>
</mapper>
解决问题:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.TestRepository">
        <!-- 新增-->
	<resultMap id="testResultMap" type="com.example.Test">
		<result column="append_package_id" jdbcType="VARCHAR" property="appendPackageId" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
	</resultMap>

        <!-- 新增 resultMap 属性-->
	<select id="getByPeisNoInStation" resultType="com.example.Test" resultMap="testResultMap">
		select
			ids
		from test
	</select>
</mapper>
属性解释:
resultMap:
column:字段名
jdbcType:数据库字段类型
property:实体对应字段名
typeHandler:类型处理器
标签: 暂无
最后更新:2025年4月27日

Akim

犇 骉 Java、C#、Python、Go、Android、MiniProgram、Bootstrap、Vue2

点赞
< 上一篇
下一篇 >

Copyright © 2025 aianran.com All Rights Reserved.

免责申明 | 隐私政策 | 服务条款 | 关于我们

黔ICP备2023008200号-1

贵公网安备 52010202003594号