###今天查询记录时,发现重复查询结果时出现空记录的状况 web
###查看控制台信息,只有红色框选部分有进行查询数据,而其余没有。然而上图可看出有两条数据是能展示出来的,故有多是mybatis缓存命中的。 缓存
###所以在mapper文件中加入flushCache="true" useCache="false"mybatis
<select id="querySuppliers" flushCache="true" useCache="false" resultType="cn.com.ebidding.web.yzPurchaseMain.dao.model.QueryYzResultModel"> select t1.id id,t2.company_name name from lib_suppliers t1, sys_company t2 where t1.is_deleted = '0' and t2.is_deleted = '0' and t1.company_id = t2.id and t1.agent_id = #{agentId} and t1.id in <foreach item="item" index="index" collection="ids" open="(" separator="," close=")"> #{item} </foreach> </select>
###问题解决 app
<font color=red size=12>总结:</font> ####(1) 当为select语句时:3d
-
flushCache默认为false,表示任什么时候候语句被调用,都不会去清空本地缓存和二级缓存。code
-
useCache默认为true,表示会将本条语句的结果进行二级缓存。blog
####(2) 当为insert、update、delete语句时:it
-
flushCache默认为true,表示任什么时候候语句被调用,都会致使本地缓存和二级缓存被清空。io
-
useCache属性在该状况下没有。class