setmeal cache
This commit is contained in:
@@ -3,6 +3,7 @@ package com.sky;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
@@ -10,6 +11,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement //开启注解方式的事务管理
|
||||
@EnableCaching
|
||||
@Slf4j
|
||||
public class SkyApplication {
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -43,6 +44,7 @@ public class SetmealController {
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
|
||||
public Result insert(@RequestBody SetmealDTO setmealDTO){
|
||||
log.info("新增套餐: {}",setmealDTO);
|
||||
setmealService.insert(setmealDTO);
|
||||
@@ -56,6 +58,7 @@ public class SetmealController {
|
||||
*/
|
||||
@DeleteMapping
|
||||
@ApiOperation("批量删除套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result delete(@RequestParam List<Long> ids){
|
||||
log.info("批量删除套餐: {}",ids);
|
||||
setmealService.deleteBatch(ids);
|
||||
@@ -82,6 +85,7 @@ public class SetmealController {
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("修改套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result update(@RequestBody SetmealDTO setmealDTO){
|
||||
log.info("修改套餐: {}",setmealDTO);
|
||||
setmealService.updateWithSetmealDishes(setmealDTO);
|
||||
@@ -96,6 +100,7 @@ public class SetmealController {
|
||||
*/
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("套餐起售停售")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||
log.info("套餐起售停售: 状态:{},ID:{}",status,id);
|
||||
setmealService.startOrStop(status,id);
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -26,6 +27,7 @@ public class SetmealController {
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("select setmeal by categoryId")
|
||||
@Cacheable(cacheNames = "setmealCache",key = "#categoryId")
|
||||
public Result<List<Setmeal>> list(Integer categoryId){
|
||||
log.info("select setmeal by categoryId :{}", categoryId);
|
||||
List<Setmeal> setmealList = setmealService.selectSetmealByCategoryId(categoryId);
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user