1.引入依赖包
<dependency>
<groupId>net.sf.ehcache</groupId>
<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>
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();
}
----
spring mvc+tomcat源码分析视频(链接复制在浏览器打开)
https://study.163.com/course/courseMain.htm?share=2&shareId=480000001919582&courseId=1209399899&_trace_c_p_k2_=6d81bc445e9c462ab8d6345e40f6b0bf