ehcache

来源:互联网 发布:常用协议端口号 编辑:程序博客网 时间:2024/06/06 15:49
   net.sf.ehcache   ehcache   2.7.5   com.googlecode.ehcache-spring-annotations   ehcache-spring-annotations   1.2.0bean.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 *  */@Servicepublic 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());}}@Overridepublic 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);}@Overridepublic 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);}}
0 0
原创粉丝点击