ehcache

xiaoxiao2021-02-28  108

net.sf.ehcache ehcache 2.7.5 com.googlecode.ehcache-spring-annotations ehcache-spring-annotations 1.2.0 bean.xml(spring配置文件)中加入 创建ehcache.xml package com.hyq.console.publish.service.impl; import java.util.HashMap; import java.util.List; import javax.annotation.Resource; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.hyq.common.hyqobject.HyqPageParam; import com.hyq.console.publish.entity.Article; import com.hyq.console.publish.mapper.ArticleMapper; import com.hyq.console.publish.service.ArticleService; /** * * @author 515848218@qq.com * */ @Service public class ArticleServiceImpl implements ArticleService { @Resource(name = "articleMapper") private ArticleMapper articleMapper; @Override @CacheEvict(value="springEhcache", key="'getlist'+#article.getItemId()") public boolean addArticle(Article article) { try { int i = articleMapper.insertSelective(article); if (i > 0) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; } @Override @CacheEvict(value="springEhcache", key="'getlist'+#article.getItemId()") public boolean updateArticle(Article article) { try { int i = articleMapper.updateByPrimaryKeySelective(article); if (i > 0) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; } @Override @CacheEvict(value="springEhcache", key="'getlist'+#article.getItemId()") public void delete(Article article) throws Exception { if (article != null) { articleMapper.deleteByPrimaryKey(article.getId()); } } @Override public Article getArticle(Integer articleId) { return articleMapper.selectByPrimaryKey(articleId); } @Override @Cacheable(value="springEhcache", key="'getlist'+#hpp.getKeywordb()") public List getList(HyqPageParam hpp) { System.out.println("=================================非缓存=============================="); return articleMapper.getList(hpp); } @Override public int getTotal(HyqPageParam hpp) { return articleMapper.getTotal(hpp); } @Override @Cacheable(value="springEhcache", key="'getlist'+#itemId") public List getListByItemId(Integer itemId, Integer nums) { HashMap hm = new HashMap (); hm.put("itemId", itemId); hm.put("nums", nums); return articleMapper.getListByItemId(hm); } }
转载请注明原文地址: https://www.6miu.com/read-67069.html

最新回复(0)