淘淘商城項目補充(2)商品上架和下架功能實現


上架下架以及編輯功能等等實現,網上好像並沒有類似比較完善的文章,誒。。。。。這么多做這個商城項目的難道老師不實現你就不實現了嗎???我這里是批評一下那些在網上寫淘淘商城系列步驟文章的人,我覺得你把步驟告訴別人了也是害別人,所以我覺得大家如果想做這個項目的話可以自己去看視頻,不要去看別人寫的啥一步一步帶你做淘淘商城的文檔,當然學習完之后,你可以適當寫一寫總結的文章。

1,分析上架和下架操作js

這里注意你的請求刪除操作的url是什么。
上架操作的url為:“/rest/item/reshelf”
下架操作的url為:“/rest/item/instock”

另外我們可以看到這里“ids”參數保存了要刪除的商品的id.ids可以是數組,所以我們考慮通過@RequestParam接收ids的值到一個Long類型的數組中。
將商品的狀態改為上架或者下架實際上就是改變商品狀態的值也就是上架就是將status的值改為1.下架就是改為2
商品狀態的值
然后通過循環數組調用逆向工程生成的updateByPrimaryKeySelective方法執行上下架操作。
上架操作js
下架操作js

2,interface層


    /** * 商品下架 */
    E3Result dropoffItem(@RequestParam("ids") long[] itemId, TbItem item);

    /** * 商品上架 */
    E3Result upperoffItem(@RequestParam("ids") long[] itemId, TbItem item);

3,service層

    /** * 下架商品 */
    @Override
    public E3Result dropoffItem(long[] itemId, TbItem item) {
        for (long l : itemId) {
            item = itemMapper.selectByPrimaryKey(l);
            item.setStatus((byte) 2);
            //創建時間不變
            item.setCreated(item.getCreated());
            //更新日期改變
            item.setUpdated(new Date());
            itemMapper.updateByPrimaryKeySelective(item);
        }

        return E3Result.ok();
    }

    /** * 上架商品 */
    @Override
    public E3Result upperoffItem(long[] itemId, TbItem item) {
        for (long l : itemId) {
            item = itemMapper.selectByPrimaryKey(l);
            item.setStatus((byte) 1);
            item.setCreated(item.getCreated());
            item.setUpdated(new Date());
            itemMapper.updateByPrimaryKeySelective(item);
        }

        return E3Result.ok();
    }

4,controler

    // 上架商品
    @RequestMapping(value = "/rest/item/reshelf", method = RequestMethod.POST)
    @ResponseBody
    private E3Result upperoffItem(@RequestParam("ids") long []itemId, TbItem item) {
        E3Result result = itemService.upperoffItem(itemId, item);
        return result;
    }

    // 下架商品
    @RequestMapping(value = "/rest/item/instock", method = RequestMethod.POST)
    @ResponseBody
    private E3Result dropoffItem(@RequestParam("ids") long []itemId, TbItem item) {
        E3Result result = itemService.dropoffItem(itemId, item);
        return result;
    }

最終的效果





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM