1. Abra a configuração global do MybatisPlus:
#二级缓存
mybatis-plus.global-config.configuration.map-underscore-to-camel-case= true
mybatis-plus.global-config.configuration.cache-enabled=true
2. No arquivo xml correspondente, adicione a configuração:
<?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.mapper.TableMapper">
<cache eviction="FIFO" flushInterval="60000" size="1024" readOnly="true" />
</mapper>
3. Se houver uma interface de gravação que não requer cache secundário, você pode adicioná-la no local correspondente: useCache = "false"
<select id="getCount" resultType="int" useCache="false">
select count(1) from table
</select>
Observação: para adicionar xml de cache secundário, a entidade correspondente precisa implementar a interface serializável