@Service
public class CacheService {
/**
-
查询缓存,缓存的名字是testList,用key来标识
-
@param key
-
@return
*/
@Cacheable(cacheNames = “testList” , key = “#key”)
public List testCache(String key){
List list = new ArrayList<>();
list.add(“a”);
list.add(“b”);
list.add(“c”);
list.add(key);
return list;
}
/**
-
修改缓存,缓存的名字是testList,用key来标识
-
@param key
-
@return
*/
@CachePut(cacheNames = “testList” , key = “#key”)
public List testPutCache(String key){
List list = new ArrayList<>();
list.add(“1”);
list.add(“2”);
list.add(“3”);
list.add(key);
return list;
}
}
======================================================================
在启动类上添加缓存扫描注解
package com.youyou;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@MapperScan(“com.youyou.*”)//将项目中对应的mapper类的路径加进来就可以了
@EnableCaching //如果想启动缓存,需要加此注解
public class WorldMainApplication {
public static void main(String[] args) {
//启动项目
SpringApplication.run(WorldMainApplication.class, args);
}
}
到此为止缓存服务已经创建完成。
来让我们测试一下!
package com.youyou.address;
import com.youyou.address.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
/**
-
//TODO 添加类/接口功能描述
-
@author 刘朋
-
date 2018-09-06
*/
@Api(description = “第一个接口”)
@RestController
@RequestMapping(“/hello”)
public class HelloWorldController {
@Autowired
private CacheService cacheService ;
@ApiOperation(value = “测试缓存” )
@GetMapping(“/testCache”)
public String testCache(){
//第一次中缓存中查询
List test = cacheService.testCache(“test”);
System.out.println(test);
//修改缓存中的值
最后
面试题文档来啦,内容很多,485页!
由于笔记的内容太多,没办法全部展示出来,下面只截取部分内容展示。
1111道Java工程师必问面试题
MyBatis 27题 + ZooKeeper 25题 + Dubbo 30题:
Elasticsearch 24 题 +Memcached + Redis 40题:
Spring 26 题+ 微服务 27题+ Linux 45题:
Java面试题合集:
Elasticsearch 24 题 +Memcached + Redis 40题:
[外链图片转存中…(img-DtCQajz4-1721155587151)]
Spring 26 题+ 微服务 27题+ Linux 45题:
[外链图片转存中…(img-v0yPQ8mW-1721155587152)]
Java面试题合集:
[外链图片转存中…(img-MywG4uj6-1721155587152)]