Mybatis拦截器执行顺序

时间:2018-06-15 03:13:31

标签: java mybatis interceptor

我在 mybatis-config.xml 中定义了两个拦截器。

var mealDataDetail = ( _dbContext.Meal.Where(m => m.IsDeleted == 0 && m.UserId == userId).ToList()
                           .GroupJoin(_dbContext.MealImage.Where(i => i.IsDeleted == 0  && i.MealType == (int)mealType).ToList(), p => p.Id, r => r.MealId, (p, rs) => new { p, rs })
                           .GroupJoin(_dbContext.MealMenu.Where(i => i.IsDeleted == 0 && i.MealType == (int)mealType).ToList(), prs => prs.p.Id, c => c.MealId, (prs, cs) => new MealDataDetail
                           {
                               MealId = prs.p.Id,

                               MealData = new MealData
                               {
                                   MealImages = prs.rs.Select(im => im.Image),
                                   Description = prs.p.BreakfastDescription,
                                   Time = prs.p.BreakfastTime,
                                   TimeRequired = prs.p.BreakfastTimeRequired,
                                   Appitite = prs.p.BreakfastAppetite,
                                   Status = prs.p.BreakfastStatus == 1,
                                   Calorie = prs.p.BreakfastCalorie,
                               },
                           }));

实施两个拦截器。

<plugins>
    <plugin interceptor="cn.common.interceptor.DbInterceptor"/>
    <plugin interceptor="cn.common.interceptor.MybatisInterceptor"/>
</plugins>

执行更新方法后, MybatisInterceptor 首次执行。

但我想首先执行 DbInterceptor 拦截器,我该怎么办?

1 个答案:

答案 0 :(得分:0)

MyBatis中,后一个插件将首先被执行,所以我认为你只需要更改插件的配置顺序:

改变
<plugins>
    <plugin interceptor="cn.common.interceptor.DbInterceptor"/>
    <plugin interceptor="cn.common.interceptor.MybatisInterceptor"/>
</plugins>

<plugins>
    <plugin interceptor="cn.common.interceptor.MybatisInterceptor"/>
    <plugin interceptor="cn.common.interceptor.DbInterceptor"/>
</plugins>

可以在 CSDN

找到更多详细信息