Java Web Development_ Realization of shopping cart function

I haven't touched the shopping cart before, and I don't know what to do with the shopping cart, so I queried a lot of information and summarized the function realization of the shopping cart.

There are three ways to query the data:

1. Realize shopping cart with cookie;

2. Realize shopping cart with session;

3. Use cookies and database (shopping cart information persistence) to realize shopping cart;

=========================================================================

Analyze the advantages and disadvantages of these three methods:

1. A shopping cart with cookies is not ideal. Imagine that if the browser of the client disables cookies,

This method will miscarry here

2. Save the shopping cart information in the session. This is only available in a session. If the user does not log in, or after logging in, add the shopping cart and close the browser

Or after logging out, all the shopping carts added before have miscarried

3. This is the way I want to say here

Main processes:

A. Data flow before user login: when the user adds a shopping cart to his favorite goods without logging in to the system, we can save the shopping cart information at this time

To cookies, this will involve the addition and modification of cookies; That is, if there is no corresponding cookie in the cookie before, add the cookie.

If there is a corresponding cookie in the cookie, it is necessary to modify the cookie (this involves the user adding shopping cart for the same commodity multiple times).

B. Data flow after the user logs in: after the user logs in, the first thing the system does is to obtain the corresponding cookies. If there are relevant shopping cart cookies, the shopping cart will be deleted

The information is persisted by the corresponding user, either added or modified. (add operation: add the shopping cart corresponding to the user if there is no corresponding information; modify operation: similar,

If the shopping cart information of the corresponding user exists, modify it). After logging in, users can also add shopping carts. However, here, they are not added to cookies, but directly persisted to

In the database. Note: the data after the user logs in are all related to the database.

=========================================================================

Code part:

=========================================================================

Note:

 
                                     addToShoppingCart()   (cashTicket ==  || cashTicket.getId() ==  || cashTicket.getId() < 1 write("nullId" }   (q ==  || q == ""   q = String.valueOf(1 }    Cookie cookies[] =  (cookies ==  || cookies.length < 0   System.out.println("there is no any cookie .." }     (getUserInSession() ==   flag =    (c.getName().equals(Conf.IDUONA_CASHTICKET_COOKIE_STARTNAME +   Integer oldValue = Integer newValue = Integer.valueOf(oldValue +  flag =       addCookie(Conf.IDUONA_CASHTICKET_COOKIE_STARTNAME +          write("success" }    CashTicket cashTicketTemp =  ShoppingCart oldShoppingCart = oldShoppingCart.setAmount(oldShoppingCart.getAmount() +  write("success"  }  ShoppingCart shoppingCartTemp =     shoppingCartTemp.setCreateTime(    write("success"                   readShoppingCartFromCookie()  System.out.println("======================================================" Cookie cookies[] =  (cookies ==  || cookies.length < 0    }   System.out.println("haha there are many cookies :" + c.getName() + " " +                 Cookie cookie =  cookie.setMaxAge(2 * 60 * 60 * 1000);                  c.setMaxAge(2 * 60 * 60 * 1000);             ( != Cookie cookies[] =  (cookies !=      String name = Integer amount = Integer ct_id = Integer.valueOf(name.substring(name.lastIndexOf("_") + 1 CashTicket temp = ShoppingCart shoppingCartTemp =   ( !=    ShoppingCart oldShoppingCart =   }       shoppingCartTemp.setCreateTime(                      Cookie cookies[] =  (cookies ==  || cookies.length < 0   System.out.println("there is no any cookie .." }  System.out.println("开始删除cookies.."   c.setMaxAge(0);      } 

这是部分代码....

效果:

用户没有登录的情况下

用户登录了以后:

数据库里面的情况:

登录前数据

========================================================

More reading,and english is important.

I'm Hongten

大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。Hongten博客排名在100名以内。粉丝过千。Hongten出品,必是精品。

E | hongtenzone@foxmail.com  B | 

========================================================

总结

以上是

编程之家为你收集整理的java web开发_购物车功能实现全部内容,希望文章能够帮你解决java web开发_购物车功能实现所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

编程之家官方1群
编程之家官方2群

编程之家官方4群





  • 上一篇:java开发_快速搜索本地文件_小应用下一篇:java web开发_购物车数据封装及数据



猜你在找的Java相关文章

【实战】利用多线程优化查询百万级数据
前言 日常开发中,难免会遇到需要查询到数据库所有记录的业务场景,在索引完善的情况下,当数据量达到百万级别或者以上的时候,全表查询就需要耗费不少的时间,这时候我们可以从以下几个方向着手优化 优化sql

【设计模式】汉堡中的设计模式——观察者模式
【设计模式】汉堡中的设计模式——观察者模式 情景带入 对于爱吃麦当劳的我来说,自然是不想错过各种动态,可是我又不可能【无时无刻】的蹲在店里等新品吧(还是要搬砖的) 那么有没有一种好的方法,在麦当劳【推



@RequestParam,@RequestBody,@ResponseBody,@PathVariable注解的一点小总结
一、前提知识: http协议规定一次请求对应一次响应,根据不同的请求方式,请求的内容会有所不同; 发送GET请求是没有请求体的,参数会直接拼接保留到url后一并发送; 而POST请求是带有请求体的,带

Java中的重载和重写
关于Java中的重载与重写,每一个java人肯定都学习过,这里就再梳理一遍,加深一下印象,忘记的时候拿出来看一看就好了 重载与重写的区别 重载发生在同一个类里面,同一个方法,拥有不同的参数列表,不同的



每日一记:关于Arrays.asList和Collections.unmodifiableList的一点理解
1、正常创建一个List,对List进行操作 List&lt;Integer&gt; collect = Stream.of(1 ,3 ,5 ,7 ,9).collect(Collectors.toL

Java8——Stream流式操作的一点小总结
我发现,自从我学了Stream流式操作之后,工作中使用到的频率还是挺高的,因为stream配合着lambda表达式或者双冒号(::)使用真的是优雅到了极致!今天就简单分(搬)享(运)一下我对strea



性能优化之数据库篇
性能优化-数据库篇1 首先我们要谈论什么是性能? 吞吐和延迟 没有量化就没有改进 :监控和度量指标可以指导我们从哪里入手 80/20原则:先优化性能瓶颈的地方 过早的优化是万恶之源:选择合适的优化时机

分布式缓存方案
一、从数据说起 我们再做缓存之前需要把数据先分好类 按变化频率: 静态数据:一般不变的,类似于字典表 准静态数据:变化频率很低,部门结构设置,全国行政区划数据 中间状态数据:一些计算的可复用中间数据,







PHPJavaJava SEPythonNumPyC#C&C++RubyVBasp.NetGoPerlnettygRPCDjangoDelphiJsp.NET CoreSpringFlaskSpringbootSpringMVCLuafastadminLaravelMybatisAspGroovyThinkPHPYii

微信公众号搜索 “ 程序精选 ” ,选择关注!
微信公众号搜 "程序精选"关注

  • • 【实战】利用多线程优化查询百
  • • 【设计模式】汉堡中的设计模式
  • • String s1 = new String("
  • • @RequestParam,@RequestBody,
  • • Java中的重载和重写
  • • elasticsearch7.6.1版本+jsoup
  • • 每日一记:关于Arrays.asList和
  • • Java8——Stream流式操作的一点
  • • 加密配置文件里面的敏感数据
  • • 性能优化之数据库篇
  • • 分布式缓存方案
  • • 超详细kafka教程来啦



  • • java-接口和抽象类的联系和区别
  • • java-单例详解
  • • java网络编程(TCP详解)
  • • java网络编程(UDP详解)
  • • java集合(List集合与Map集合的
  • • java的XML解析(DOM4J技术)
  • • 详解java开发环境搭建
  • • 利用JAVA实现DES加密算法
  • • Java基本类型与包装类详细解析
  • • Java打印和打印预览机制实例代

javapythonjQuerylinuxC#AndroiddockerIOSaspUbuntucentosrubyC++asp.net前端perlJSON正则oraclexml表达式VBPostgresqlMVCCASP.NET程序应用lua学习Servervb.netShellSQLite.Netreact配置native是否数据VIMdatabasevueString字符串开发命令笔记运行twitter-bogolang没有vbdjangojenkins类测试为什么c#通过数组模式问题Unix编程连接转换编译项目方法redis启动更改多个function访问加载存储验证之间

联系我们

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>