zoukankan      html  css  js  c++  java
  • asp.net通过cookie简单实现购物车功能

    1,首先建立购物车模型类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace Ants.WebPart.Models
    {
        public class ShopCarModel
        {
            public int Id { get; set; }
            public string Title { get; set; }
            public string Other { get; set; }
        }
    }

    2.实现购物车功能的两个方法:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Ants.WebPart.Models;
    using Ants.Common;
    
    namespace Ants.WebPart
    {
        public class ShopCarTask
        {
            private static string _cookieName =TextUtils.ConvertToBasic64("MyshopcarPowerByAnts");
            Ants.Provider.ISerializerProvider serializer = new Ants.Provider.JsonSerializerProvider();
            public void SetShopCar(IList<ShopCarModel> goods)
            {
               CookieUtils.Write(_cookieName,TextUtils.ConvertToBasic64(serializer.ToString(goods)));
            }
            public void SetShopCar(IList<ShopCarModel> goods, int expires)
            {
                CookieUtils.Write(_cookieName, TextUtils.ConvertToBasic64(serializer.ToString(goods)),expires);
            }
            public IList<ShopCarModel> GetShopCar()
            {
               return serializer.parse < IList < ShopCarModel >>(CookieUtils.Read(_cookieName));
            }
        }
    }

    原创文字只代表本人某一时间内的观点或结论,本人不对涉及到的任何代码担保。转载请标明出处!

  • 相关阅读:
    C++ 实现B+树
    SSM项目--
    spring+mybatis使用MapperScannerConfigurer简化配置
    SpringMVC复习总结
    MyBatis复习总结
    ajax
    几种常用页面的跳转
    MyShop-不用框架的基础javaweb项目
    jsp
    Guava 工具类之joiner的使用
  • 原文地址:https://www.cnblogs.com/leleroyn/p/2393438.html
Copyright © 2011-2022 走看看