文章缓存 redis定时转移到mongoDb
This commit is contained in:
@ -3,6 +3,7 @@ package com.ruoyi.web.controller.note;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.note.domain.NoteContentMgDb;
|
||||
import com.ruoyi.note.service.INoteRepositoryService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@ -37,20 +38,6 @@ public class NmNoteController extends BaseController
|
||||
@Autowired
|
||||
private INmNoteService nmNoteService;
|
||||
|
||||
@Autowired
|
||||
private INoteRepositoryService noteRepositoryService;
|
||||
|
||||
|
||||
//测试
|
||||
@GetMapping("/selectBymenuNote2")
|
||||
public void save() {
|
||||
NoteContentMgDb noteContentMgDb = new NoteContentMgDb();
|
||||
noteContentMgDb.setId(7L);
|
||||
noteContentMgDb.setNoteContent("宋人头2");
|
||||
noteRepositoryService.save(noteContentMgDb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户查看栏目下的所有便签
|
||||
@ -59,9 +46,8 @@ public class NmNoteController extends BaseController
|
||||
@GetMapping("/selectBymenuNote")
|
||||
public TableDataInfo selectBymenuNote(Long menuId)
|
||||
{
|
||||
SysUser sysUser=getAuthUser();
|
||||
NmNote nmNote= new NmNote();
|
||||
nmNote.setUserId(sysUser.getUserId());
|
||||
nmNote.setUserId(getAuthUser().getUserId());
|
||||
nmNote.setMenuId(menuId);
|
||||
startPage();
|
||||
List<NmNote> list = nmNoteService.selectNmNoteList(nmNote);
|
||||
@ -69,17 +55,28 @@ public class NmNoteController extends BaseController
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户新增便签
|
||||
* 用户新增便签 直接创建成功
|
||||
*/
|
||||
@PostMapping("/addUserNote")
|
||||
public AjaxResult userAddNote(@RequestBody NmNote nmNote)
|
||||
{
|
||||
SysUser sysUser=getAuthUser();
|
||||
nmNote.setUserId(sysUser.getUserId());
|
||||
|
||||
nmNote.setUserId(getAuthUser().getUserId());
|
||||
return toAjax(nmNoteService.insertNmNote(nmNote));
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时更新文章信息 不用做缓存
|
||||
*/
|
||||
@PostMapping("/userUpdateNote")
|
||||
public AjaxResult userUpdateNote(@RequestBody NmNote nmNote)
|
||||
{
|
||||
|
||||
return toAjax(nmNoteService.userUpdateNote(nmNote));
|
||||
}
|
||||
|
||||
/**
|
||||
*用户 获取便签详细信息 然后修改
|
||||
*/
|
||||
|
@ -1,11 +1,18 @@
|
||||
package com.ruoyi.web.test.controller;
|
||||
|
||||
import com.github.wujun234.uid.UidGenerator;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.note.domain.NoteContentMgDb;
|
||||
import com.ruoyi.note.service.INoteRepositoryService;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Auther: Wang
|
||||
@ -16,6 +23,16 @@ public class MongdbApplicationTests extends BaseSpringBootTest{
|
||||
@Autowired
|
||||
private INoteRepositoryService noteRepositoryService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
|
||||
@Resource
|
||||
private UidGenerator cachedUidGenerator;
|
||||
|
||||
@Resource
|
||||
private UidGenerator defaultUidGenerator;
|
||||
|
||||
/**
|
||||
* 查询所有信息
|
||||
*/
|
||||
@ -31,7 +48,7 @@ public class MongdbApplicationTests extends BaseSpringBootTest{
|
||||
@Test
|
||||
public void save() {
|
||||
NoteContentMgDb noteContentMgDb = new NoteContentMgDb();
|
||||
noteContentMgDb.setId(19L);
|
||||
noteContentMgDb.setId(15108230363503104L);
|
||||
noteContentMgDb.setNoteContent("宋人头");
|
||||
noteRepositoryService.save(noteContentMgDb);
|
||||
}
|
||||
@ -43,7 +60,7 @@ public class MongdbApplicationTests extends BaseSpringBootTest{
|
||||
@Test
|
||||
public void update() {
|
||||
NoteContentMgDb noteContentMgDb = new NoteContentMgDb();
|
||||
noteContentMgDb.setId(2L);
|
||||
// noteContentMgDb.setId(2L);
|
||||
noteContentMgDb.setNoteContent("吴很帅");
|
||||
noteRepositoryService.update(noteContentMgDb);
|
||||
}
|
||||
@ -55,4 +72,51 @@ public class MongdbApplicationTests extends BaseSpringBootTest{
|
||||
public void delete() {
|
||||
noteRepositoryService.delete(3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void addredis(){
|
||||
for (int i=0;i<10;i++){
|
||||
redisCache.setCacheObject(Constants.NM_NOTE_CONTENT+defaultUidGenerator.getUID(),i);
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void getRedis(){
|
||||
String redis= redisCache.getCacheObject("nm_note:15563127529716224");
|
||||
System.out.println("redis:"+redis);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓存文章 转义到 mgDB
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@Test
|
||||
public void redisToMgDB(){
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ token:
|
||||
# 令牌自定义标识
|
||||
header: Authorization
|
||||
# 令牌密钥
|
||||
secret: abcdefghijklmnopqrstuvwxyz
|
||||
secret: abc4abcdefghijklmnopqrstuvwxyz
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 300
|
||||
|
||||
|
Reference in New Issue
Block a user