请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

currentshop

从前台能接受到表单传过来的信息,但是到session的时候,图片描述
执行完这句shop.setShopId(currentShop.getShopId());后跳出一个页面图片描述
这句session是从shoplist中来的还是从哪?
是因为我没有从店铺进入,所以就没有session吗?

正在回答 回答被采纳积分+3

插入代码

2回答

翔仔 2020-03-16 00:48:10

代码是这样的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    private Map<String, Object> getShopManagementInfo(HttpServletRequest request) {
        Map<String, Object> modelMap = new HashMap<String, Object>();
        long shopId = HttpServletRequestUtil.getLong(request, "shopId");
        if (shopId <= 0) {
            Object currentShopObj = request.getSession().getAttribute("currentShop");
            if (currentShopObj == null) {
                modelMap.put("redirect"true);
                modelMap.put("url""/o2o/shopadmin/shoplist");
            else {
                Shop currentShop = (Shop) currentShopObj;
                modelMap.put("redirect"false);
                modelMap.put("shopId", currentShop.getShopId());
            }
        else {
            Shop currentShop = new Shop();
            currentShop.setShopId(shopId);
            request.getSession().setAttribute("currentShop", currentShop);
            modelMap.put("shopId", shopId);
            modelMap.put("redirect"false);
        }
        return modelMap;
    }

就是说需要js把shopId传过来,否则就从session里面去获取。。所以看看同学js里面有没有传入?

http://localhost:8080/o2o/shopadmin/shopmanagement?shopId=1


0 回复 有任何疑惑可以回复我~
翔仔 2020-03-12 00:28:42

是的,因为店铺和店家是一对多的关系,所以它不知道你到底选择的是哪个店铺。。如果为了测试的方便,可以直接给session写死一个

0 回复 有任何疑惑可以回复我~
  • 提问者 我总是那么的乖 #1
    但我不是在测试,这个是在productmangement的addproduct方法中的,
    if (product != null && thumbnail != null && 
            productImgList.size() > 0) {
       try {
    // 从session中获取当前店铺的Id并赋值给product,减少对前端数据的依赖
    	Shop currentShop = (Shop) 
            request.getSession().getAttribute("currentShop");
    	product.setShop(currentShop);
    回复 有任何疑惑可以回复我~ 2020-03-12 09:02:31
  • 翔仔 回复 提问者 我总是那么的乖 #2
    对啊,所以得按照常规流程走,得先选好店铺,才能对这个店铺操作呢,这样做是为了支持一个店家能管理多个店铺,所以得选择店铺才知道管理的是哪个店铺。如果一个店家对应一个店铺,得至少实现登录才可以
    回复 有任何疑惑可以回复我~ 2020-03-12 23:52:33
  • 提问者 我总是那么的乖 回复 翔仔 #3
    我看视频是先走这个页面http://localhost:8080/o2o/shopadmin/shopmanagement?shopId=1然后在开一个页面走productoperation,但是我这么下来还是null
    回复 有任何疑惑可以回复我~ 2020-03-15 16:12:13
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号