概述
按照需求设计,我们希望商铺管理者
店铺名称不能修改
店铺类别不能修改
其余信息可编辑修改
分为两步,
- 第一步前端传入shopId到后台获取商铺信息,前端展示
- 第二步修改商铺信息,提交到后台,更新商铺
ShopController
com.artisan.o2o.web.shopadmin.ShopController.java
ShopController#getShopInfoById方法
getShopInfoById
/**
*
*
* @Title: getShopInfoById
*
* @Description: 根据shopId获取shop信息, 接收前端的请求,获取shopId ,所以入参为HttpServletRequest
* @ResponseBody 不需要VIEW展现层模块,直接显示到客户端的内容。 将内容或对象作为 HTTP 响应正文返回
*
* @param request
*
* @return: Map<String,Object>
*/
@RequestMapping(value = "/getshopinfo", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> getShopInfoById(HttpServletRequest request) {
Map<String, Object> modelMap = new HashMap<String, Object>();
// shopId 为和前端约定好的变量
int shopId = HttPServletRequestUtil.getInt(request, "shopId");
try {
if (shopId >= 0) {
// 查询 ,按照设计,我们希望前端页面下拉列表中可以修改区域信息,所以需要查询出来全量的区域列表
// 对已ShopCategory而言,我们DAO层的SQL已经将shop_category_id和
// shop_category_name 查询出来,前端设置到对应的属性上即可。没有必要全部查询出来。
Shop shop = shopService.getShopById(shopId);
List<Area> areaList = areaservice.getAreaList();
modelMap.put("success", true);
modelMap.put("shop", shop);
modelMap.put("areaList", areaList);
} else {
modelMap.put("success", false);
modelMap.put("errMsg", "shopId不合法");
}
} catch (Exception e) {
modelMap.put("success", false);
modelMap.put("errMsg", e.getMessage());
}
return modelMap;
}
测试
启动tomcat,访问 http://localhost:8080/o2o/shopadmin/getshopinfo?shopId=30
返回的数据如下:
{
"shop": {
"shopId": 30,
"shopName": "优乐美",
"shopDesc": "优乐美奶茶店",
"shopAddr": "复兴街",
"phone": "123456",
"shopImg": "\\upload\\item\\shopImage\\30\\2018053001010899137.png",
"priority": null,
"createTime": 1527656467000,
"lastEditTime": 1527656467000,
"enableStatus": 0,
"advice": null,
"owner": null,
"area": {
"areaId": 1,
"areaName": "北京",
"areaDesc": null,
"priority": null,
"createTime": null,
"lastEditTime": null
},
"shopCategory": {
"shopCategoryId": 3,
"shopCategoryName": "奶茶",
"shopCategoryDesc": null,
"shopCategoryImg": null,
"priority": null,
"createTime": null,
"lastEditTime": null,
"parent": null
}
},
"success": true,
"areaList": [
{
"areaId": 2,
"areaName": "上海",
"areaDesc": "魔都",
"priority": 99,
"createTime": 1526259636000,
"lastEditTime": 1526346041000
},
{
"areaId": 1,
"areaName": "北京",
"areaDesc": "帝都",
"priority": 0,
"createTime": 1526259626000,
"lastEditTime": 1526346033000
}
]
}
检查数据,符合预期。