请稍等 ...
×

采纳答案成功!

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

老师,id为null

学完第六章后,shoplist能显示,昨天可以跳到shopmanagement,但是地址栏的shopId 是null,今天干脆跳不到shopmanagement 页面了,闪回到shoplist,


正在回答

插入代码

2回答

翔仔 2018-05-15 16:23:21

你看这里的js

shopmanagement.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$(function() {
    var shopId = getQueryString('shopId');
    var shopInfoUrl = '/o2o/shopadmin/getshopmanagementinfo?shopId=' + shopId;
    $.getJSON(shopInfoUrl, function(data) {
        if (data.redirect) {
            window.location.href = data.url;
        else {
            if (data.shopId != undefined && data.shopId != null) {
                shopId = data.shopId;
            }
            $('#shopInfo')
                    .attr('href''/o2o/shopadmin/shopoperation?shopId=' + shopId);
        }
    });
});

获取的是店铺列表页点击后传递过来的选中的当前shopId并传递给后台,后台取到shopId后设置到session里面 下次刷新页面后Session里面已经有shopId存在currentShop里面了,直接取来用就好了。同学你可以看看我的代码格式化后很容易看

0 回复 有任何疑惑可以回复我~
  • 提问者 快看喵 #1
    替换了老师的代码就好了,唯一的不同的就是,我在shopInfoUrl的'?shopId ='的等于号后面多了一个空格
    回复 有任何疑惑可以回复我~ 2018-05-15 17:57:43
  • 翔仔 回复 提问者 快看喵 #2
    同学真的不能抱有侥幸以及正好改了什么就好了的心理,要多分析一下为什么会这样,整体需要如何做,如果出问题出在哪个位置,逐渐培养自己解决和定位问题的体系
    回复 有任何疑惑可以回复我~ 2018-05-15 18:03:12
提问者 快看喵 2018-05-15 14:45:28

我的modelMap里面的shopId全部为null,为什么放不进去呢

https://img1.sycdn.imooc.com//szimg/5afa81d20001390b06690654.jpg

https://img1.sycdn.imooc.com//szimg/5afa81d20001a4e508840541.jpg


0 回复 有任何疑惑可以回复我~
  • 翔仔 #1
    这个得看同学的getshoplist方法,看看mapper里面选取店铺列表的时候,是不是有取出shopid,需要你结合控制台输出的sql信息去调试,也是一个比较简单的问题,可以抓住这个机会锻炼一下自己定位以及解决问题的能力
    回复 有任何疑惑可以回复我~ 2018-05-15 15:26:07
  • 提问者 快看喵 回复 翔仔 #2
    哇,是我mapper语句写错了,这次id出来了,然后还是跳不到shopmanagement,会闪回shoplist,我把if语句注释掉,才能跳过去
    @RequestMapping(value = "/getshopmanagementinfo",method=RequestMethod.GET)
    	@ResponseBody
    	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("redirect", false);
    			
    //		}
    		return modelMap;
    	}
    回复 有任何疑惑可以回复我~ 2018-05-15 15:45:47
  • 提问者 快看喵 回复 翔仔 #3
    long shopId = HttpServletRequestUtil.getLong(request,"shopId");
    		System.out.println(shopId);
    在下面打桩,输出shopId是-1,为什么
    没搞明白"shopId"是从哪里取的
    回复 有任何疑惑可以回复我~ 2018-05-15 16:12:44
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

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

帮助反馈 APP下载

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

公众号

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