缓存套餐业务代码开发
This commit is contained in:
@@ -4,11 +4,13 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTransactionManagement //开启注解方式的事务管理
|
@EnableTransactionManagement //开启注解方式的事务管理
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@EnableCaching //开启缓存注解
|
||||||
public class SkyApplication {
|
public class SkyApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SkyApplication.class, args);
|
SpringApplication.run(SkyApplication.class, args);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.ibatis.annotations.Delete;
|
import org.apache.ibatis.annotations.Delete;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -36,6 +37,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("新增套餐")
|
@ApiOperation("新增套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache", key = "#setmealDTO.categoryId")
|
||||||
public Result save(@RequestBody SetmealDTO setmealDTO) {
|
public Result save(@RequestBody SetmealDTO setmealDTO) {
|
||||||
setmealService.saveWithDish(setmealDTO);
|
setmealService.saveWithDish(setmealDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
@@ -60,6 +62,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@ApiOperation("批量删除套餐")
|
@ApiOperation("批量删除套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache", allEntries = true)
|
||||||
public Result delete(@RequestParam List<Long> ids){
|
public Result delete(@RequestParam List<Long> ids){
|
||||||
setmealService.deleteBatch(ids);
|
setmealService.deleteBatch(ids);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
@@ -86,6 +89,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ApiOperation("修改套餐")
|
@ApiOperation("修改套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache", allEntries = true)
|
||||||
public Result update(@RequestBody SetmealDTO setmealDTO){
|
public Result update(@RequestBody SetmealDTO setmealDTO){
|
||||||
setmealService.update(setmealDTO);
|
setmealService.update(setmealDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
@@ -94,6 +98,7 @@ public class SetmealController {
|
|||||||
|
|
||||||
@PostMapping("/status/{status}")
|
@PostMapping("/status/{status}")
|
||||||
@ApiOperation("套餐起售停售")
|
@ApiOperation("套餐起售停售")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache", allEntries = true)
|
||||||
public Result startOrStop(@PathVariable Integer status, Long id){
|
public Result startOrStop(@PathVariable Integer status, Long id){
|
||||||
setmealService.startOrStop(status, id);
|
setmealService.startOrStop(status, id);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.sky.vo.DishItemVO;
|
|||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -29,6 +30,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("根据分类id查询套餐")
|
@ApiOperation("根据分类id查询套餐")
|
||||||
|
@Cacheable(cacheNames = "setmealCache", key = "#categoryId")
|
||||||
public Result<List<Setmeal>> list(Long categoryId) {
|
public Result<List<Setmeal>> list(Long categoryId) {
|
||||||
Setmeal setmeal = new Setmeal();
|
Setmeal setmeal = new Setmeal();
|
||||||
setmeal.setCategoryId(categoryId);
|
setmeal.setCategoryId(categoryId);
|
||||||
|
|||||||
Reference in New Issue
Block a user