云笔记——笔记本模块(2)

笔记本列表的获取


笔记列表获取

当用户登录成功后加载该用户的笔记本,默认点击default
通过发送Ajax请求将获取的数据追加到页面中

<div class="modal fade in" id="modalBasic" tabindex="-1" role="dialog" aria-labelledby="modalBasicLabel" aria-hidden="false" >
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
							<h4 class="modal-title" id="modalBasicLabel">新建笔记本</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<label class="col-sm-3 control-label" for="input_notebook" style='margin-top:5px;'>笔记本名称</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="input_notebook">
								</div>
							</div>
						</div>
						<div class="modal-footer" style='margin-top:20px;'>
							<button type="button" class="btn btn-default cancle" data-dismiss="modal">取 消</button>
							<button type="button" class="btn btn-primary sure" id="btn1">创 建</button>
						</div>
					</div>
				</div>
			</div>
  1. 前端调用函数发送Ajax请求
function loadNoteBook(){
	// 防止数据库的数据追加 每次获取数据之前清除从数据库中查询的数据
	$("#first_side_right li").next().html('');
	$.ajax({
		url:"/notebook/loadNotebook",
		type:"post",
		success:function (result) {
			var map= result.data;
			var normalNotebooks = map.normal;
			$.each(normalNotebooks,function (i,v) {
				// console.log(i+"--"+v.notebookName);
				$("#first_side_right ul").append('<li class="online">' +
                    '<a class="unchecked">' +
                    '<i class="fa fa-book" title="笔记本" rel="tooltip-bottom"></i> '+v.notebookName +
                    '<button type="button" class="btn btn-default btn-xs btn_position btn_delete"><i class="fa fa-times"></i></button>' +
                    '</a></li>');
				$("#first_side_right li:last").data('notebook',v);
			})
			// 绑定特殊笔记本
			$("#rollback_button").data("notebook",map.recycle);
			$("#like_button").data("notebook",map.favorites);
			$("#action_button").data("notebook",map.action);
			$("#first_side_right li:first").data("notebook",map.default);
			// 加载完笔记本列表后加载笔记列表
            getNoteList();
		}
	})
}
  1. 控制层
  @RequestMapping("/loadNotebook")
    public Result loadNotebook(HttpSession session) {
        Result result = new Result();
        User user = (User) session.getAttribute("loginUser");
        Map<String, Object> notebookMap = notebookService.loadNotebook(user.getId());
        result.setData(notebookMap);
        return result;
    }
  1. 业务逻辑层
@Override
    public Map<String,Object> loadNotebook(String userId){
        // 获得普通笔记本的类型
        NotebookType normalType = notebookTypeDao.getNormalType();
        // 创建map集合对象 用来存储非普通笔记本
        Map<String,Object> map = new HashMap<String,Object>();
        // 床架list集合对象,用来存储普通笔记本
        List<Notebook> list = new ArrayList<Notebook>();
        List<Notebook> notebookList = notebookDao.findByUserId(userId);
        for(Notebook no : notebookList){
            if(no.getNoteTypeId().equals(normalType.getNotebookTypeId())){
                list.add(no);
            } else {
                map.put(no.getNotebookName(),no);
            }
        }
        map.put("normal",list);
        return map;
    }
  1. 持久层
 public List<Notebook> findByUserId(String userId);

笔记本列表获取完成

如果需要看bean以及xml的配置点击超链接
笔记本重命名

猜你喜欢

转载自blog.csdn.net/weixin_42765270/article/details/84973305