diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 27fd2b3..5447202 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,10 +6,16 @@
-
-
+
+
+
+
+
-
+
+
+
+
@@ -143,6 +149,8 @@
+
+
diff --git a/pom.xml b/pom.xml
index 65d6531..f76777c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,8 +84,15 @@
org.springframework.boot
spring-boot-starter-data-redis
+
+
+ org.springframework.boot
+ spring-boot-starter-cache
+
+
+
8
8
diff --git a/src/main/java/cn/edu/hactcm/TakeOutApplication.java b/src/main/java/cn/edu/hactcm/TakeOutApplication.java
index d4cfecf..d8fd211 100644
--- a/src/main/java/cn/edu/hactcm/TakeOutApplication.java
+++ b/src/main/java/cn/edu/hactcm/TakeOutApplication.java
@@ -5,11 +5,13 @@ 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;
@Slf4j
@SpringBootApplication
@ServletComponentScan("cn.edu.hactcm.filter")
@MapperScan("cn.edu.hactcm.mapper")
+@EnableCaching//开启Spring Cache 注解方式的缓存功能
public class TakeOutApplication {
public static void main(String[] args) {
SpringApplication.run(TakeOutApplication.class, args);
diff --git a/src/main/java/cn/edu/hactcm/common/R.java b/src/main/java/cn/edu/hactcm/common/R.java
index 4bcaaa7..6d14877 100644
--- a/src/main/java/cn/edu/hactcm/common/R.java
+++ b/src/main/java/cn/edu/hactcm/common/R.java
@@ -1,6 +1,8 @@
package cn.edu.hactcm.common;
import lombok.Data;
+
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -9,7 +11,7 @@ import java.util.Map;
* @param
*/
@Data
-public class R {
+public class R implements Serializable {
private Integer code; //编码:1成功,0和其它数字为失败
diff --git a/src/main/java/cn/edu/hactcm/cotroller/SetmealController.java b/src/main/java/cn/edu/hactcm/cotroller/SetmealController.java
index a41fd42..f9eb826 100644
--- a/src/main/java/cn/edu/hactcm/cotroller/SetmealController.java
+++ b/src/main/java/cn/edu/hactcm/cotroller/SetmealController.java
@@ -12,6 +12,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@@ -38,6 +40,7 @@ public class SetmealController {
*/
@PostMapping
@Transactional
+ @CacheEvict(value = "setmealCache",allEntries = true)
public R saveMealDish(@RequestBody SetmealDto setmealDto){
setmealService.saveWithDish(setmealDto);
return R.success("添加成功!");
@@ -78,6 +81,7 @@ public class SetmealController {
* @return
*/
@DeleteMapping
+ @CacheEvict(value = "setmealCache",allEntries = true)
public R deleteWithDish(@RequestParam List ids){
setmealService.removeWithDish(ids);
return R.success("删除成功");
@@ -89,6 +93,7 @@ public class SetmealController {
* @return
*/
@GetMapping("/list")
+ @Cacheable(value = "setmealCache",key = "#setmeal.categoryId+'_'+#setmeal.status")
public R> get(Setmeal setmeal){
Long categoryId = setmeal.getCategoryId();
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 0aa8245..6727c77 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -14,6 +14,9 @@ spring:
host: localhost
port: 6379
database: 0
+ cache:
+ redis:
+ time-to-live: 1800000 #设置缓存数据的过期时间
mybatis-plus:
configuration:
#在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
diff --git a/target/classes/application.yml b/target/classes/application.yml
index 0aa8245..6727c77 100644
--- a/target/classes/application.yml
+++ b/target/classes/application.yml
@@ -14,6 +14,9 @@ spring:
host: localhost
port: 6379
database: 0
+ cache:
+ redis:
+ time-to-live: 1800000 #设置缓存数据的过期时间
mybatis-plus:
configuration:
#在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
diff --git a/target/classes/cn/edu/hactcm/TakeOutApplication.class b/target/classes/cn/edu/hactcm/TakeOutApplication.class
index b462b70..86bc30a 100644
Binary files a/target/classes/cn/edu/hactcm/TakeOutApplication.class and b/target/classes/cn/edu/hactcm/TakeOutApplication.class differ
diff --git a/target/classes/cn/edu/hactcm/common/R.class b/target/classes/cn/edu/hactcm/common/R.class
index a24036a..d031679 100644
Binary files a/target/classes/cn/edu/hactcm/common/R.class and b/target/classes/cn/edu/hactcm/common/R.class differ
diff --git a/target/classes/cn/edu/hactcm/cotroller/DishController.class b/target/classes/cn/edu/hactcm/cotroller/DishController.class
index aa12676..1c7bd28 100644
Binary files a/target/classes/cn/edu/hactcm/cotroller/DishController.class and b/target/classes/cn/edu/hactcm/cotroller/DishController.class differ