baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.44k stars 4.31k forks source link

[错误报告]: 遇到的问题 mybatisplus执行count()方法时,需要对查询字段加密,但是在拦截器中获取不到实体对象 #6576

Closed runnerFeng closed 1 week ago

runnerFeng commented 2 weeks ago

确认

当前程序版本

3.5.9

问题描述

// 支持 LambdaQueryWrapper if (paramMap.containsKey(Constants.WRAPPER) && paramMap.get(Constants.WRAPPER) instanceof AbstractWrapper) { AbstractWrapper queryWrapper = (AbstractWrapper) paramMap.get(Constants.WRAPPER); // Class<?> entityClass = queryWrapper.getEntityClass(); Class<?> entityClass = getEntityClass(queryWrapper); // TODO count方法获取不到class if (entityClass!=null && annotateWithEncrypt(entityClass)) { encryptWrapperForQuery(entityClass, queryWrapper, boundSql); } }

详细堆栈日志

No response

runnerFeng commented 2 weeks ago

private Class<?> getEntityClass(AbstractWrapper queryWrapper) { // 使用反射从 LambdaQueryWrapper 中获取实体类的类型 Class entityClass = queryWrapper.getEntityClass(); if (entityClass == null){ // queryWrapper. } return entityClass; }

miemieYaho commented 2 weeks ago

你set实体了吗?

runnerFeng commented 2 weeks ago

count(new LambdaQueryWrapper<HedgeExchange>().eq(xxx))>0 改成这种 count(new LambdaQueryWrapper<>(HedgeExchange.class).eq(xxx))>0 可以了 第一种写法可以支持获取entityClass吗,这种写法我看设置为null了 感谢回复!

miemieYaho commented 2 weeks ago

你翻翻Java看看他能获取不