MyBatis注解方式和XML方式能不能同时开启二级缓存呢?

ShopMapper.java 

@Mapper

@CacheNamespace(blocking = true)

public interface ShopMapper {

    //省略其他注解方式的查询方法...

    //查询单个

    @Select("select * from t_shop where id=#{id}")

    Shop selectById(Integer id);

    //删除

    @Delete("delete  from t_shop where id=#{id}")

    int deleteShop(int id);

    //修改,xml方式

    int updateShop(Shop shop);

}

ShopMapper.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper

        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.rgb.demosystem.mapper.ShopMapper">


    <update id="updateShop" parameterType="Shop" >

        update t_shop

        <set>

            <if test="dorm != null and dorm != ''">

                dorm=#{dorm},

            </if>

            <if test="finishCount != null and finishCount != ''">

                finishCount=#{finishCount},

            </if>

            where id=#{id}

        </set>
    </update>
</mapper>

像这种注解和XML方式两种同时使用的情况下,我使用查询数据的方法时二级缓存是有效果的,但是使用更新数据(就是这里用XML方式的)后,没有刷新缓存,我再执行之前的查询数据方法,得到的还是旧的数据。请问有没有解决方法?

应该是可以的, 你在接口添加注解和在xml中使用<cache /> 效果是一样的 ; mybatis的二级缓存是根据 namespace来的 , 这两种方式同属于一个namespace , 你可以验证一下