mybatis注解配置缓存的方法

mapper文件

package it.com.db;


import java.util.List;
import java.util.Map;
import org.apache.ibatis.cache.decorators.LruCache;
import com.mysql.jdbc.util.LRUCache;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;


@CacheNamespace(
size=100,eviction=LruCache.class,implementation=org.mybatis.caches.ehcache.EhcacheCache.class)
public interface IuserMapper {

@Select("select * from username")
@Options(useCache=true)
public List findAll();
}



conf文件









     
   

   
       
           
           
           
               
               
               
               
           

       

   

   
       
     
   

    




ehcache.xml文件


maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>


log4j.properties 文件


### ÉèÖÃLoggerÊä³ö¼¶±ðºÍÊä³öÄ¿µÄµØ ###
log4j.rootLogger = all, stdout,logfile


### °ÑÈÕÖ¾ÐÅÏ¢Êä³öµ½¿ØÖÆ̨ ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout


### °ÑÈÕÖ¾ÐÅÏ¢Êä³öµ½Îļþ£ºjbit.log ###
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=d\:\\tt.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%l %F %p %m%n


IuserMapper文件  

package it.com.db;


import java.util.List;
import java.util.Map;
import org.apache.ibatis.cache.decorators.LruCache;
import com.mysql.jdbc.util.LRUCache;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;


@CacheNamespace(
size=100,eviction=LruCache.class,implementation=org.mybatis.caches.ehcache.EhcacheCache.class)
public interface IuserMapper {

@Select("select * from username")
@Options(useCache=true)
public List findAll();




}





你可能感兴趣的:(mybatis注解,配置缓存,mybatis)