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
總結
以上是生活随笔為你收集整理的2016-7-4收藏夹接口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3、数据类型一:strings
- 下一篇: app和外部应用的关联及应用举例