一.需求分析
- 规格参数编辑页面的所有数据都来源于datagrid
- 表格中数据只能选择一行
- 服务端返回EgoResult判断修改是否成功
二.代码实现
- 在src/item/param/TbItemParamDao.go添加修改函数,创建时间不修改,更新时间为当前时间
//修改func updParamByIdDao(param TbItemParam) int{ count,err:=commons.Dml("update tb_item_param set item_cat_id=?,param_data=?,updated=now() where id=?",param.ItemCatId,param.ParamData,param.Id) if err!=nil{ fmt.Println(err) return -1 } return int(count)}
- 在src/item/param/TbItemParamService.go中添加修改业务
//编辑规格参数func updateParamService(id int, itemCatId int, paramData string) (e commons.EgoResult) { param := TbItemParam{Id: id, ItemCatId: itemCatId, ParamData: paramData} count := updParamByIdDao(param) if count > 0 { e.Status = 200 } return}
- 在src/item/param/TbItemParamController.go中添加控制器函数和url映射
//编辑规格参数func updateParamController(w http.ResponseWriter,r *http.Request){ id,_:=strconv.Atoi(r.FormValue("id")) itemCatId,_:=strconv.Atoi(r.FormValue("itemCatId")) paramData:=r.FormValue("paramData") er:=updateParamService(id,itemCatId,paramData) b,_:=json.Marshal(er) w.Header().Set(commons.HEADER_CONTENT_TYPE,commons.JSON_HEADER) w.Write(b)}
commons.Router.HandleFunc("/item/param/edit",updateParamController)//规格参数修改