生活随笔
收集整理的這篇文章主要介紹了
云笔记收藏笔记
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天做云筆記項目中的收藏筆記部分時,卡在了檢查是否已經收藏過該筆記這里,想了很久,終于解決了。具體來說,就是通過shareId+userId拼接起來作為收藏筆記的id,這樣就不會出現甲收藏了A筆記,乙在沒有收藏A筆記的情況下,不能收藏A筆記的bug了。
public NoteResult collectNote(String shareId, String userId) {NoteResult result = new NoteResult();//檢查是否已經收藏過該筆記Note note1 = noteDao.findByNoteId(shareId + userId);if(note1 != null) {result.setStatus(1);result.setMsg("該筆記已被收藏過");return result;}Share share = shareDao.findById(shareId);Note note = new Note();note.setCn_note_body(share.getCn_share_body());note.setCn_note_create_time(System.currentTimeMillis());note.setCn_note_id(share.getCn_share_id() + userId);note.setCn_note_last_modify_time(System.currentTimeMillis());note.setCn_note_title(share.getCn_share_title());note.setCn_user_id(userId);noteDao.save2(note);result.setStatus(0);result.setMsg("收藏筆記成功");return result;}
總結
以上是生活随笔為你收集整理的云笔记收藏笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。