mybatis - 如何从 Mybatis 获取 db 列值进行分片?
问题描述
我使用 Mybatis 访问 db,有些表是通过 id 和 hash 算法分片的。
我想写一个Mybatis intecepter来自动更改表名,它需要获取分片列的值。
表实体:
@Data
@TableName("m_user")
public class User {
@TableId(type = IdType.AUTO)
private Integer id;
private String name;
private Integer age;
}
用户映射器 sql:
@Select("select * from m_user where id = #{id2} and name = #{name2};")
List<User> selectByIdAndName(Integer id2, String name2);
我用boundSql.getParameterObject()
andboundSql.getParameterMappings()
来检查,但不能确定分片列id
是否在sql中,然后获取分片列的值。
ParameterMappings 值和 ParameterObject 值在这里:
parameter mapping:ParameterMapping{property='id2', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}
parameter mapping:ParameterMapping{property='name2', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}
params:{id2=1, param1=1, name2=name1, param2=name1}
参数是Mapper函数参数,但我需要分片列id
和值,程序只能获取id2
或param1
。
如何从 Mybatis 获取 db 列和值?
解决方案
推荐阅读
- mysql - MySQL-基于多列输出“其他”列
- javascript - 将道具传递给父母
- java - Java 8拆分字符串并在地图内创建地图
- mysql - 在我的 sql < 8 中获取树文件夹结构的父母和孩子,并且没有 CTE
- amazon-web-services - AWS API Gateway 删除响应标头
- javascript - 尝试设置 href 时 element.setAttribute 不是函数
- php - 如何在 Woocommerce 中禁用或删除持久购物车?
- c++ - 出现错误“运行时检查失败 #2 - 围绕变量 'midtermgrade' 的堆栈已损坏。”
- javascript - HTML 表单使整个页面崩溃
- android - 在三星手机上进入 PIP(画中画)模式时出现错误“设备不支持画中画模式”