note_cloud--编辑区域中的“保存笔记”--更新笔记信息
来源:互联网 发布:win10系统安装mac os 编辑:程序博客网 时间:2024/06/06 18:28
更新笔记信息
-------------------------------------------------------------------------------------------------------------------------------
发送ajax请求
发送事件:“保存笔记”按钮点击时间(静态绑定)
请求参数:笔记ID(id)、笔记标题(title)、笔记内容(body)
请求地址:/note/update.do
服务器处理
UpdateNoteController(id,title,body)
UpdateNoteService.updateNote(id,title,body)
NoteDao.update(Note)--注意此出由于有多个参数,所以采用对象
cn_note(根据笔记的ID更新笔记的 title、body、最后更新时间)
ajax回调处理
success:对被更新的笔记名称进行更新
获取选中的li:
<li><a class="check"></a></li>
var $li = $("#note_ul a[class='checked']").parent()
注意:在绑定笔记单击事件时候可以将编辑笔记区域的title和body清空
-------------------------------------------------------------------------------------------------------------------------------
Dao接口:
//在编辑笔记区域根据笔记ID修改笔记,返回影响数据的条数public int updateNote(Note note);注意:Mybatis中Dao中抽象方法最多传递一个参数,当传递多个参数时,可以使用对象
-------------------------------------------------------------------------------------------------------------------------------
映射文件:
<!-- 在编辑笔记区域根据笔记ID修改笔记 --> <update id="updateNote" parameterType="cn.tedu.cloud_note.entity.Note"> update cn_note set cn_note_title = #{cn_note_title}, cn_note_body = #{cn_note_body}, cn_note_last_modify_time = #{cn_note_last_modify_time} where cn_note_id = #{cn_note_id} </update>注意:根据笔记的ID更新笔记的 title、body、最后更新时间
-------------------------------------------------------------------------------------------------------------------------------
业务层接口:
//在编辑笔记区域根据笔记ID修改笔记信息public NoteResult<Object> updateNote(String noteId,String noteTitle,String noteBody);
-------------------------------------------------------------------------------------------------------------------------------
业务层实现类:
//在编辑笔记区域根据笔记ID修改笔记信息public NoteResult<Object> updateNote(String noteId,String noteTitle,String noteBody) {//创建note参数Note note = new Note();note.setCn_note_id(noteId);note.setCn_note_title(noteTitle);note.setCn_note_body(noteBody);//最后一次更新笔记的时间(Long包装类型)note.setCn_note_last_modify_time(System.currentTimeMillis());NoteResult<Object> result = new NoteResult<Object>();//根据笔记ID更新笔记int rows = dao.updateNote(note);if(rows == 1){//更新笔记成功result.setStatus(0);result.setMsg("保存笔记成功");return result;}result.setStatus(1);result.setMsg("更新笔记失败");return result;}注意:笔记的最后修改时间为Long类型,可以使用当前系统时间
-------------------------------------------------------------------------------------------------------------------------------
控制层Controller:
package cn.tedu.cloud_note.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import cn.tedu.cloud_note.entity.Note;import cn.tedu.cloud_note.service.NoteService;import cn.tedu.cloud_note.util.NoteResult;@Controller@RequestMapping("/note")public class UpdateNoteController {@Resource(name="noteService")private NoteService service;@RequestMapping("/update.do")@ResponseBodypublic NoteResult<Object> execute(String noteId,String noteTitle,String noteBody){NoteResult<Object> result = service.updateNote(noteId,noteTitle,noteBody);return result;}}
-------------------------------------------------------------------------------------------------------------------------------
HTML部分代码:
$(function(){//加载笔记列表loadUserBooks();//动态绑定笔记本单击事件--此处若使用$("#book_ul li").click(function(){})没有反应$("#book_ul").on("click","li",loadBookNotes);//绑定单击笔记加载笔记信息功能$("#note_ul").on("click","li",loadNote);//编辑笔记区域的"保存笔记"按钮绑定事件update(需要三个参数id、title、body)$("#save_note").click(function(){//获取笔记的ID,check样式在<a>上,不是在li上var noteId = $("#note_ul a[class='checked']").parent().data("noteId");//当笔记被选中,即存在noteId时,点击"保存笔记曹发送ajax请求"if(noteId){//获取笔记的titlevar noteTitle = $("#input_note_title").val().trim();//获取笔记的bodyvar noteBody = um.getContent();//发送ajax请求$.ajax({url:path + "/note/update.do",type:"post",data:{"noteId":noteId,"noteTitle":noteTitle,"noteBody":noteBody},dataType:"json",success:function(result){if(result.status == 0){//更新成功//重新定义<a>标签 var str = ('<i class="fa fa-file-text-o" title="online" rel="tooltip-bottom"></i>'+noteTitle +'<button type="button" class="btn btn-default btn-xs btn_position btn_slide_down"><i class="fa fa-chevron-down"></i></button>');}//重新定义标签<a>(也可以清空标签后再追加)var $a = $("#note_ul a[class='checked']").html(str);}, error:function(){alert("保存笔记失败");}}); }});});
注意:在编辑笔记区域单击"保存笔记时候",若该区域显示了笔记(即有笔记id的情况下)该按钮才起作用,同时笔记本列表区域中点击切换笔记本的时候,编辑笔记区域会还原
- note_cloud--编辑区域中的“保存笔记”--更新笔记信息
- note_cloud--单击笔记使笔记标题和内容显示在编辑区域
- note_cloud--加载笔记列表
- note_cloud--创建笔记
- note_cloud--笔记分享功能
- note_cloud--删除笔记功能
- note_cloud--显示笔记下拉菜单
- 笔记 区域
- note_cloud--搜索笔记功能(已经分享了的笔记)(两个功能)
- jQuery学习笔记--jqGrid的使用方法(编辑,删除,更新,新增)
- JQuery可编辑的表格,并更新到数据库笔记
- jQuery学习笔记--jqGrid的使用方法(编辑,删除,更新,新增)
- Hibenate笔记 之 hibernate的 保存 更新 异步问题
- [Android笔记] Sina API保存Oauth验证信息
- 笔记92--将崩溃信息保存到本地(上)
- 笔记94--将崩溃信息保存到本地(下)
- android学习笔记(21)用户配置信息的保存
- Sqoop学习笔记 --- python保存 Sqoop 打印的信息
- python_面向对象三
- struct device
- Lintcode 背包问题
- (C++)继承、菱形继承和虚继承的那些事儿
- (五) u-boot 命令执行过程解析与添加自定义命令
- note_cloud--编辑区域中的“保存笔记”--更新笔记信息
- 摘抄
- 图---存储方式二
- 汉诺塔问题
- Android判断软键盘弹出并隐藏的简单完美解决方法(推荐)
- Linux中用户与口令的管理
- 流:简单的压缩和解压流程
- 循环结构
- csu D(1973): 给自己出题的小X