inotgo.com


Tool version compatibility problem
Before developing shopping carts , First, we should clarify the relationship between several key classes
Correct

Step 1 : Class diagram   
Step 2 : Class diagram   

First, the meaning of each category :
1. Product Products
2. User Users
3. Order order
4. OrderItem Order item

front 3 It's easy to understand , Order item Need to explain .

For example, you are under a treasure One order , This order includes
Black silk stockings One
Inflatable doll Two
whip Three
Candles Four


A record is an order item , Corresponding to a commodity , And the number of purchases .
 Class diagram
1. The relationship between product and order item is One to many
A product , Corresponding to multiple order items .
An order item , Corresponding to a product
2. Relationship between order item and order Many to one
There are multiple order items in an order
An order item , It will only appear in one order
3. The relationship between orders and users : Many to one
An order , Can only belong to one user
A user , You can place multiple orders
 Class diagram


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2020-06-20 OrderItemAddServlet Something went wrong , It's just that the product added here doesn't show
JCW




OrderItemAddServlet Something went wrong , It's just that the product added here doesn't show , I put all the jump addresses inside / Removed , Other functions can be used
 Loading
package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.OrderItem;
import bean.Product;
import dao.ProductDAO;

public class OrderItemAddServlet extends HttpServlet{
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		int num = Integer.parseInt(request.getParameter("num"));
		int pid = Integer.parseInt(request.getParameter("pid"));
		
		Product p = new ProductDAO().getProduct(pid);
		
		OrderItem oi = new OrderItem();
		
		oi.setNum(num);
		oi.setProduct(p);
		
		List<OrderItem> ois = (List<OrderItem>) request.getSession().getAttribute("ois");
		
		if(null == ois) {
			ois = new ArrayList<OrderItem>();
			request.getSession().setAttribute("ois", ois);
		}
		
		
		  boolean found = false; for(OrderItem orderItem : ois) {
		  if(orderItem.getProduct().getId() == oi.getProduct().getId()) {
		  orderItem.setNum(orderItem.getNum()+oi.getNum()); found = true; break; } }
		 
		
		if(!found)
		
		ois.add(oi);
		
		response.sendRedirect("listOrderItem");
	}

}
 
               


1 One answer

Rookies love strength
Answer time :2020-08-06
The problem may not be OrderItemAddServlet Go ahead , It is estimated that there is something wrong with your previous product list , What he shows is that the parameters you passed are unrecognized



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2020-03-26 Can this shopping cart be used as an item ?
Mitsuha_

I'm going to find an internship this year , Can this shopping cart be written in your resume as a small item ? How big projects can be written in your resume ?




2 One answer

CRUD-MASTER
Answer time :2020-08-16
Forget this , I'm sorry

Stranger dust z
Answer time :2020-04-15
I can never , This is just a small demo , It can't be counted as a project



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-02-19 Performance The top is higher than the bottom, right . If yes , Is it necessary .
2019-05-20 Can the webmaster ask you a question
2018-08-31 Cute girl said she didn't understand Why buy these things


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 5 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about J2EE- Shopping Cart - Class relationships Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot