2016-7-4收藏夹接口

/*
     * 用户查看收藏列表
     */
    public String selectcollection() throws ParseException {
        // 通过用户id查询到收藏夹中该用户收藏的所有商品的id
        collect = userservice.findByUidColl(uid);
        List<Goods> list2 = new ArrayList<Goods>();
        List<Collection> list1 = new ArrayList<Collection>();
        List<Goods> list3 = new ArrayList<Goods>();
        if (collect != null) {
            for (Collection c1 : collect) {
                collection = new Collection(c1.getGid(), c1.getUid());
                list1.add(collection);
            }
            for (int i = 0; i < list1.size(); i++) {
                goods = goodsservice.findGoodsById1(list1.get(i).getGid());
                list3.add(goods);
            }
            for (Goods c2 : list3) {
                goods1 = new Goods(c2.getGoodsId(), c2.getGoodsName(),
                        c2.getSourceId(), c2.getGoodsPrice(), c2.getUnitCost(),
                        c2.getPhotoUrl(), c2.getWeblinkurl(), c2.getMonsales(),
                        c2.getZhekou(), c2.getIsWeblink());
                list2.add(goods1);
                if (goods1 == null) {
                    code = 1;
                    msg = "获取收藏列表失败";
                } else {
                    code = 0;
                    msg = "获取收藏列表成功";
                }
            }
        } else {
            code = 1;
            msg = "您的收藏列表为空";
        }
        map = new HashMap<String, Object>();
        map.put("data", list2);
        map.put("code", code);
        map.put("msg", msg);
        gridjson = JSONObject.toJSONString(map);
        return SUCCESS;
    }

    /*
     * 用户删除收藏商品
     */
    public String deletecollection() throws ParseException {
        String[] id;
        goodsObj = request.getParameter("gid");
        id = goodsObj.split(",");
        for (int i = 0; i < id.length; i++) {
            collection1 = userservice.select(Integer.parseInt(id[i]), uid);
            if (collection1 != null) {
                collection2 = userservice.deletecoll(collection1);
                if (collection2 == null) {
                    code = 1;
                    msg = "删除失败";
                } else {
                    code = 0;
                    msg = "删除成功";
                }
            } else {
                code = 1;
                msg = "商品为空";
            }
        }
        map = new HashMap<String, Object>();
        map.put("code", code);
        map.put("msg", msg);
        gridjson = JSONObject.toJSONString(map);
        return SUCCESS;
    }

    /*
     * 我的足迹列表
     */
    public String footmark() throws ParseException {
        String[] id;
        goodsObj = request.getParameter("gid");
        id = goodsObj.split(",");
        List<Goods> list1 = new ArrayList<Goods>();
        for (int i = 0; i < id.length; i++) {
            goods = goodsservice.findGoodsById(Integer.parseInt(id[i]));
            goods1 = new Goods(goods.getGoodsId(), goods.getGoodsName(),
                    goods.getSourceId(), goods.getGoodsPrice(),
                    goods.getUnitCost(), goods.getPhotoUrl(),
                    goods.getWeblinkurl(), goods.getMonsales(),
                    goods.getZhekou(), goods.getIsWeblink());
            list1.add(goods1);
            if (goods1 == null) {
                code = 1;
                msg = "获取足迹列表失败";
            } else {
                code = 0;
                msg = "获取足迹列表成功";
            }
        }
        map = new HashMap<String, Object>();
        map.put("data", list1);
        map.put("code", code);
        map.put("msg", msg);
        gridjson = JSONObject.toJSONString(map);
        System.out.println(gridjson);
        return SUCCESS;
    }
}
/*
     * 用户一键收藏、取消收藏商品
     */
    public String addcollection() throws ParseException {
        collection1 = userservice.select(gid, uid);
        if (collection1 == null) {
            coll = new Collection();
            coll.setGid(gid);
            coll.setUid(uid);
            collection = userservice.addcoll(coll);
            if (collection == null) {
                code = 1;
                msg = "收藏失败";
            } else {
                code = 0;
                msg = "收藏成功";
            }
        } else {

            collection2 = userservice.deletecoll(collection1);
            if (collection2 == null) {
                code = 1;
                msg = "取消收藏失败";
            } else {
                code = 0;
                msg = "取消收藏成功";
            }
        }
        map = new HashMap<String, Object>();
        map.put("code", code);
        map.put("msg", msg);
        gridjson = JSONObject.toJSONString(map);
        return SUCCESS;
    }
总结:如果访问接口不进action的方法,struts配置文件有问题,如果进方法,但是不往服务层进,说明映射文件未配置,批量删除列表数据时上传参数为字符串,如23,32,43    足迹列表信息跟用户无关,只是保存在软件上的浏览记录

原文地址:https://www.cnblogs.com/JOEH60/p/5641442.html