一、目录接口
二、实现代码
1、EhCache.java
package com.aeolusway;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching //使缓存可用
@MapperScan("com.aeolusway.mapper")
public class EhCache {
public static void main(String[] args) {
SpringApplication.run(EhCache.class, args);
}
}
2、UserController.java
package com.aeolusway.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aeolusway.mapper.UserMapper;
import com.aeolusway.model.User;
@RestController
public class UserController {
@Autowired
private UserMapper userMapper;
@Autowired
private CacheManager cacheManager;
@RequestMapping("/find")
public User findUser(int id){
return userMapper.findUser(id);