spring中缓存配置
来源:互联网 发布:软件项目管理模板 编辑:程序博客网 时间:2024/05/30 23:46
1.引入依赖包
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.5.1</version>
<artifactId>ehcache-core</artifactId>
<version>2.5.1</version>
</dependency>
2.配置
<cache:annotation-driven/>
<!-- generic cache manager -->
<bean id="cacheManager"
class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="default" />
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="nurseCache" />
</set>
</property>
</bean>
<!-- generic cache manager -->
<bean id="cacheManager"
class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="default" />
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="nurseCache" />
</set>
</property>
</bean>
3.编码
//存到缓存中的key值是查询参数
@Cacheable(value="nurseCache",key="#idItems")
public List<Nurse> queryNurseListByIdCol(String idItems) {
System.out.println("查询数据库");
System.out.println(idItems);
if(idItems == null || "".equals(idItems)){
return null;
}
String url = apiQueryNursesByIds+"?idItems="+idItems;
String result = HttpUtil.sendGet(url, "utf-8");
System.out.println(result);
HttpNurseListResult resultList = JSON.parseObject(result, HttpNurseListResult.class);
if(resultList == null){
return null;
}
int success = resultList.getSuccess();
if(success != 1){
return null;
}
return resultList.getData();
}
public List<Nurse> queryNurseListByIdCol(String idItems) {
System.out.println("查询数据库");
System.out.println(idItems);
if(idItems == null || "".equals(idItems)){
return null;
}
String url = apiQueryNursesByIds+"?idItems="+idItems;
String result = HttpUtil.sendGet(url, "utf-8");
System.out.println(result);
HttpNurseListResult resultList = JSON.parseObject(result, HttpNurseListResult.class);
if(resultList == null){
return null;
}
int success = resultList.getSuccess();
if(success != 1){
return null;
}
return resultList.getData();
}
0 0
- spring中缓存配置
- spring中缓存配置(完善)
- spring配置EHcache缓存
- spring+hibernate缓存配置
- spring缓存配置
- spring配置ehchace缓存
- redis spring缓存配置
- 缓存 spring xml配置
- spring redis缓存配置
- spring配置eache缓存
- spring缓存配置
- 如何在JPA,Hibernate 和 Spring 中配置 Ehcache 缓存
- 关于Spring中ehcahce实现注解缓存的配置
- Spring Boot中缓存注解的配置与使用
- Hibernate+spring缓存机制配置
- Hibernate+spring缓存机制配置
- spring整合redis缓存配置
- spring+mybatis+ehcache配置缓存
- SQL中的case when then else end用法
- C语言小白
- struts中的action类
- 揭开Socket编程的面纱
- 欢迎使用CSDN-markdown编辑器
- spring中缓存配置
- Jetson TX1板载相机opencv调用打开
- 为什么要写博客
- hihoCoder--1110 正则表达式(区间dp)
- C++使用构造器初始化对象的两种方式
- 将Eclipse的项目转到Android Studio上
- 程序员如何解决问题,小策略大帮助
- Ubuntu升级后只能进入grub界面的解决方法
- java web项目监听session查看在线人数