Giter Club home page Giter Club logo

Comments (4)

chaobingliu avatar chaobingliu commented on August 18, 2024

老师,如果通过实现InnerInterceptor接口无法实现对查询的数据作处理,请问有什么好的方法可以达到相同的目的呢?

from mybatis-plus.

chaobingliu avatar chaobingliu commented on August 18, 2024

我想可能是因为executor.query多次执行导致的,但如果不执行executor.query的话,该怎么获取到查询的数据呢?

from mybatis-plus.

xxx-tea avatar xxx-tea commented on August 18, 2024

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.

uncarbon97 avatar uncarbon97 commented on August 18, 2024

使用多个插件时,需要注意它们的顺序。建议的顺序是:

多租户、动态表名
分页、乐观锁
SQL 性能规范、防止全表更新与删除
总结:对 SQL 进行单次改造的插件应优先放入,不对 SQL 进行改造的插件最后放入。

https://baomidou.com/plugins/

from mybatis-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.