最近在看到一段代码
@Autowired
private MessageDAO messageDAO;
@Test
public void testSave() {
Message message = Message.builder().id(ObjectId.get()).msg("你好")
.sendDate(new Date())
.status(1)
.from(new User(1001L, "zhangsan"))
.to(new User(1002L, "lisi"))
.build();
this.messageDAO.saveMessage(message);
message = Message.builder()
.id(ObjectId.get())
.msg("你也好")
.sendDate(new Date())
.status(1)
.to(new User(1001L, "zhangsan"))
.from(new User(1002L, "lisi"))
.build();
this.messageDAO.saveMessage(message);
}
这里面的【this.messageDAO.saveMessage(message);】并没有重名的情况,为啥要在前面加个this呢?
我自己尝试了不加this,也是可以插入数据的
@Test
public void testss(){
Message message = Message.builder().id(ObjectId.get()).msg("测试1")
.sendDate(new Date())
.status(1)
.from(new User(1001L, "zhangsan"))
.to(new User(1002L, "lisi"))
.build();
messageDAO.saveMessage(message);
}