Comments (4)
老师,如果通过实现InnerInterceptor接口无法实现对查询的数据作处理,请问有什么好的方法可以达到相同的目的呢?
from mybatis-plus.
我想可能是因为executor.query多次执行导致的,但如果不执行executor.query的话,该怎么获取到查询的数据呢?
from mybatis-plus.
InnerInterceptor本来就是对sql进行拦截修改的,如果你想不影响分页功能的话做一写sql记录的话,可以使用mybaits的Interceptor来进行拦截,可以参考下我以前写过的
@configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mybatisPlusInterceptor;
}
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> configuration.addInterceptor(new TagFillInterceptor());
}
}
@Intercepts(@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class}))
public class TagFillInterceptor implements Interceptor {
@OverRide
public Object intercept(Invocation invocation) throws Throwable {
// 先执行查询,获取结果
Object result = invocation.proceed();
// 对查询结果进行处理,填充List
if (result instanceof List) {
List resultList = (List) result;
if (!resultList.isEmpty() && resultList.get(0) instanceof Course) {
fillTags(resultList);
}
}
return result;
}
private void fillTags(List<?> entities) {
TagService tagService = SpringUtil.getBean(TagService.class);
for (Object entity : entities) {
Course course = (Course) entity;
List<String> tagList = course.getTagList();
if (CollUtil.isNotEmpty(tagList)) {
List<Tag> tags = tagService.listByIds(tagList);
course.setTags(tags);
}
}
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
}
from mybatis-plus.
使用多个插件时,需要注意它们的顺序。建议的顺序是:
多租户、动态表名
分页、乐观锁
SQL 性能规范、防止全表更新与删除
总结:对 SQL 进行单次改造的插件应优先放入,不对 SQL 进行改造的插件最后放入。
from mybatis-plus.
Related Issues (20)
- 3.5.6版本以上InExpression为什么摒弃了itemsList,导致 IN 的时候没括号,可以怎么解决 HOT 5
- [错误报告]: 数据变更记录插件BUG HOT 1
- [错误报告]: 数据权限插件DataPermissionInterceptor和setDecrBy(负数)冲突
- [功能改进]: 是否可以增加逻辑删除开关 HOT 1
- 使用分页插件时,用$来做动态查询后台提示warn HOT 2
- [错误报告]: 描述 typeHandler 字段进行修改时,未生效 HOT 2
- [错误报告]: 描述Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '''. Cause: org.apache.ibatis.ognl.OgnlException HOT 1
- [错误报告]: 在@async方法中updateById拼接的tenantId =0,造成更新数据失败 HOT 1
- [功能改进]: savebatch是否可以改成 INSERT INTO xxx(aa, bb, cc) VALUES(..) HOT 1
- [错误报告]: 描述xml自定义查询中jacksonTypeHandler无法将json字段转为List HOT 1
- [错误报告]: 描述 net.sf.jsqlparser.parser.CCJSqlParserUtil#parseStatement 解析sql 超时,默认时间是 6秒 HOT 1
- 配合dynamic-datasource 并且使用从数据库加载数据源方式,map-underscore-to-camel-case失效 HOT 3
- [错误报告]: com.microsoft.sqlserver.jdbc.SQLServerException: 列名 'id' 无效 HOT 3
- [功能改进]: 描述 LambdaQueryWrapper 条件构造方法的condition和val计算问题 3.5.6 版本 HOT 1
- [错误报告]: IService.updateById(bean)时,where子句生成错误 HOT 5
- [错误报告]: 使用LambdaQueryWrapper中出现can not find lambda cache for this property HOT 4
- [功能改进]: mapper.xml 或 @Select注解中怎么支持 db-config.shcema HOT 2
- [错误报告]: 使用mybatisbatch对象报错,springboot3.0.6,mybatisplus3.5.7 HOT 1
- 多数据源,HikariCP连接池,如何自定义控制SQL执行时间 HOT 2
- [错误报告]: 字段类型为JSONObject无法映射 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mybatis-plus.