fix: 刷新首页新闻缓存

This commit is contained in:
xiongxiaoyang 2023-04-18 08:58:30 +08:00
parent 9ed465784a
commit cab350dbb2

View File

@ -1,26 +1,21 @@
package com.java2nb.novel.controller; package com.java2nb.novel.controller;
import java.util.List; import com.java2nb.common.config.CacheKey;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import io.swagger.annotations.ApiOperation;
import com.java2nb.novel.domain.NewsDO;
import com.java2nb.novel.service.NewsService;
import com.java2nb.common.utils.PageBean; import com.java2nb.common.utils.PageBean;
import com.java2nb.common.utils.Query; import com.java2nb.common.utils.Query;
import com.java2nb.common.utils.R; import com.java2nb.common.utils.R;
import com.java2nb.novel.domain.NewsDO;
import com.java2nb.novel.service.NewsService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/** /**
* 新闻表 * 新闻表
@ -33,8 +28,11 @@ import com.java2nb.common.utils.R;
@Controller @Controller
@RequestMapping("/novel/news") @RequestMapping("/novel/news")
public class NewsController { public class NewsController {
@Autowired @Autowired
private NewsService newsService; private NewsService newsService;
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
@GetMapping() @GetMapping()
@RequiresPermissions("novel:news:news") @RequiresPermissions("novel:news:news")
@ -89,6 +87,7 @@ public class NewsController {
@RequiresPermissions("novel:news:add") @RequiresPermissions("novel:news:add")
public R save(NewsDO news) { public R save(NewsDO news) {
if (newsService.save(news) > 0) { if (newsService.save(news) > 0) {
redisTemplate.delete(CacheKey.INDEX_NEWS_KEY);
return R.ok(); return R.ok();
} }
return R.error(); return R.error();
@ -103,6 +102,7 @@ public class NewsController {
@RequiresPermissions("novel:news:edit") @RequiresPermissions("novel:news:edit")
public R update(NewsDO news) { public R update(NewsDO news) {
newsService.update(news); newsService.update(news);
redisTemplate.delete(CacheKey.INDEX_NEWS_KEY);
return R.ok(); return R.ok();
} }
@ -115,6 +115,7 @@ public class NewsController {
@RequiresPermissions("novel:news:remove") @RequiresPermissions("novel:news:remove")
public R remove(Long id) { public R remove(Long id) {
if (newsService.remove(id) > 0) { if (newsService.remove(id) > 0) {
redisTemplate.delete(CacheKey.INDEX_NEWS_KEY);
return R.ok(); return R.ok();
} }
return R.error(); return R.error();
@ -129,6 +130,7 @@ public class NewsController {
@RequiresPermissions("novel:news:batchRemove") @RequiresPermissions("novel:news:batchRemove")
public R remove(@RequestParam("ids[]") Long[] ids) { public R remove(@RequestParam("ids[]") Long[] ids) {
newsService.batchRemove(ids); newsService.batchRemove(ids);
redisTemplate.delete(CacheKey.INDEX_NEWS_KEY);
return R.ok(); return R.ok();
} }