SpringBoot集成MongoDB
This commit is contained in:
@ -3,7 +3,8 @@ package com.ruoyi.web.controller.note;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.ruoyi.note.domain.NoteContentMgDb;
|
||||
import com.ruoyi.note.service.INoteRepositoryService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -36,6 +37,20 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户查看栏目下的所有便签
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.ruoyi.web.test.controller;
|
||||
|
||||
import com.ruoyi.note.domain.NoteContentMgDb;
|
||||
import com.ruoyi.note.service.INoteRepositoryService;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Auther: Wang
|
||||
* @Date: 2020/10/08 19:11
|
||||
* 功能描述:
|
||||
*/
|
||||
public class MongdbApplicationTests extends BaseSpringBootTest{
|
||||
@Autowired
|
||||
private INoteRepositoryService noteRepositoryService;
|
||||
|
||||
/**
|
||||
* 查询所有信息
|
||||
*/
|
||||
@Test
|
||||
public void findAll() {
|
||||
List<NoteContentMgDb> all = noteRepositoryService.findAll();
|
||||
System.out.println(all.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增信息
|
||||
*/
|
||||
@Test
|
||||
public void save() {
|
||||
NoteContentMgDb noteContentMgDb = new NoteContentMgDb();
|
||||
noteContentMgDb.setId(19L);
|
||||
noteContentMgDb.setNoteContent("宋人头");
|
||||
noteRepositoryService.save(noteContentMgDb);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改信息
|
||||
*/
|
||||
@Test
|
||||
public void update() {
|
||||
NoteContentMgDb noteContentMgDb = new NoteContentMgDb();
|
||||
noteContentMgDb.setId(2L);
|
||||
noteContentMgDb.setNoteContent("吴很帅");
|
||||
noteRepositoryService.update(noteContentMgDb);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除信息
|
||||
*/
|
||||
@Test
|
||||
public void delete() {
|
||||
noteRepositoryService.delete(3);
|
||||
}
|
||||
}
|
@ -15,12 +15,8 @@ import com.ruoyi.web.controller.system.SysLoginController;
|
||||
import com.ruoyi.web.controller.yunbookmark.SqBookmarkController;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
@ -31,10 +27,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -55,3 +55,14 @@ spring:
|
||||
wall:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
|
||||
|
||||
#mongodb
|
||||
data:
|
||||
mongodb:
|
||||
uri: mongodb://localhost:27017/ChangQuYun
|
||||
#设置了密码
|
||||
# spring.data.mongodb.uri=mongodb://admin:123456@192.168.56.128:27017/admin
|
||||
#格式: mongodb://账号:密码@ip:端口/数据库?认证数据库
|
||||
# 配置MongoTemplate的执行日志
|
||||
# logging.level.org.springframework.data.mongodb.core=debug
|
||||
|
@ -146,3 +146,6 @@ uid:
|
||||
boostPower: 3 # RingBuffer size扩容参数, 可提高UID生成的吞吐量, 默认:3
|
||||
paddingFactor: 50 # 指定何时向RingBuffer中填充UID, 取值为百分比(0, 100), 默认为50
|
||||
#scheduleInterval: 60 # 默认:不配置此项, 即不实用Schedule线程. 如需使用, 请指定Schedule线程时间间隔, 单位:秒
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user