SSM Project Day03-部门/组织管理【修改数据】从页面到页面

一、从页面上拿数据

dept_list.html

function doLoadEditUI() {
//   ①设定页面标题
	var title;
	if($(this).hasClass("btn-add")){
		title="添加部门";
	}else if($(this).hasClass("btn-update")){
		title="修改部门";
		//按行读取数据
		var rowData=doGetCheckedItem();//交给函数处理
		if(!rowData){
			alert("请您先选择");
			return
		}
		$("#mainContentId").data("rowData",rowData);
	}
	
	//获取页面信息
	function doGetCheckedItem() {
	//获取tr里的内容
		var tr=$("tbody input[type='radio']:checked").parents("tr");
		var rowData=tr.data("rowData");
		console.log(rowData);
		return rowData;
	}

dept_edit.html

$(function () {
      //加载上级部门树结构
      $(".form-horizontal")
          .on("click",".load-sys-dept",doLoadZtreeNodes);     //展示树结构
      
      $(".box-footer").on("click",".btn-save",doSaveOrUpdate)   //保存
                    .on("click",".btn-cancel",doCancel);      //取消
      $("#treeLayer")
          .on("click",".btn-confirm",doSetSelectNode)  //确定按钮
          .on("click",".btn-cancel",doHideTree);       //隐藏树结构

      var data=$("#mainContentId").data("rowData");   //如果是修改按行读取数据
      if(data)doInitEditFormData(data);               //初始化数据
  })


  function doInitEditFormData() {
          $("#nameId").val(data.name);
          $("#noteId").val(data.note);
          $("#sortId").val(data.sort);
          $("#parentId").data("parentId",data.parentId);
          $("#parentId").val(data.parentName);

  }

二、Dao

//     修改
    int updateObject(SysDept entity);

三、mapper.xml

  <update id="updateObject" parameterType="com.jt.sys.SysDept">
         update sys_depts
         set
           name=#{name},
           note=#{note},
           sort=#{sort},
           parentId=#{parentId},
           modifiedUser=#{modifiedUser},
           modifiedTime=now()
        where id=#{id}
    </update>

四、Service

    int updateObject(SysDept entity);
//    修改
    @Override
    public int updateObject(SysDept entity) {
//        合法性验证
        if(entity==null){
            throw new ServiceException("保存对象不能为空");
        }
//        部门名不能为空
        if(StringUtils.isEmpty(entity.getName())){
            throw new ServiceException("部门名不能为空");
        }
//        调用方法
        int rows = sysDeptDao.updateObject(entity);
        return rows;
    }

五、Controller

//    修改
    @RequestMapping("doUpdateObject")
    @ResponseBody
    public JsonResult doUpdateObject(SysDept entity){
        sysDeptService.updateObject(entity);
        return new JsonResult("update ok");
    }

检测一下吧!
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_31416771/article/details/88678898