一.需求分析
- 把 02资料/章节208商品上架 中内容粘贴到项目中
- 商品下架本质就是修改tb_item表中status=1
- 之前在完成商品删除时已经在TbItemDao.go中编写了修改status值的函数,直接复用即可
- 根据页面中内容,客户端给服务端发起请求后要求服务器端返回数据已经是EgoResult对应的json数据
二. 代码实现
- 在TbItemService中添加函数实现商品上架
//商品上架func instockService(ids string) (e commons.EgoResult){ count:=updStatusByIdsDao(strings.Split(ids,","),1) if count>0{ e.Status=200 } return}
- 在TbItemController中添加函数,并修改Itemhandler()函数中内容
//商品上架func instockController(w http.ResponseWriter, r *http.Request) { ids:=r.FormValue("ids") er:=instockService(ids) b,_:=json.Marshal(er) w.Header().Set("Content-Type","application/json;charset=utf-8") w.Write(b)}func ItemHandler() { commons.Router.HandleFunc("/showItem", showItemController) commons.Router.HandleFunc("/item/delete", delByIdsController) commons.Router.HandleFunc("/item/instock", instockController)}