Get the App
SLTechnology News&Howtos  ›  Development  › 

How to imitate Tmall online Mall by Java

Shulou Source: shulou.com Published: 2022-06-02 15:45:57 10月02日 Update

Editor to share with you how to achieve Java to imitate Tmall online mall, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

I. brief introduction of the project

Features:

Front desk:

* user module

* Classification module

* Product module

* Shopping cart module

* order module

Background:

* Manager module

* Classification management module

* Commodity management module

* order module

II. Project operation

Environment configuration: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (both supported by IntelliJ IDEA,Eclispe,MyEclispe,Sts)

Project technology: JSP + C3P0 + Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload and so on.

Basic information operation code: basic information operation: public abstract class BaseBackServlet extends HttpServlet {/ * add * / public abstract String add (HttpServletRequest request, HttpServletResponse response, Page page); / * delete * / public abstract String delete (HttpServletRequest request, HttpServletResponse response, Page page); / * update * / public abstract String update (HttpServletRequest request, HttpServletResponse response, Page page); / * modify * / public abstract String edit (HttpServletRequest request, HttpServletResponse response, Page page) / * display * / public abstract String list (HttpServletRequest request, HttpServletResponse response, Page page); protected CategoryDAO categoryDAO = new CategoryDAO (); protected OrderDAO orderDAO = new OrderDAO (); protected OrderItemDAO orderItemDAO = new OrderItemDAO (); protected ProductDAO productDAO = new ProductDAO (); protected ProductImageDAO productImageDAO = new ProductImageDAO (); protected PropertyDAO propertyDAO = new PropertyDAO (); protected PropertyValueDAO propertyValueDAO = new PropertyValueDAO (); protected ReviewDAO reviewDAO = new ReviewDAO (); protected UserDAO userDAO = new UserDAO () Override protected void service (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {try {/ * get paging information * / int start = 0; int count = 5; try {start = Integer.parseInt (req.getParameter ("page.start")); count = Integer.parseInt (req.getParameter ("page.count")) } catch (Exception e) {} Page page = new Page (start, count); / * with reflection, call the corresponding method * / String method = (String) req.getAttribute ("method"); Method m = this.getClass () .getMethod (method, HttpServletRequest.class, HttpServletResponse.class, Page.class) String redirect = m.invoke (this, req, resp, page). ToString (); / * make the corresponding client or server jump according to the returned value of the method, or output only the string * / if (redirect.startsWith ("@")) {resp.sendRedirect (redirect.substring (1)) } else if (redirect.startsWith ("%")) {resp.getWriter (). Print (redirect.substring (1));} else {req.getRequestDispatcher (redirect) .forward (req, resp);}} catch (NoSuchMethodException e) {e.printStackTrace ();} catch (IllegalAccessException e) {e.printStackTrace () } catch (InvocationTargetException e) {e.printStackTrace ();}} public InputStream parseUpload (HttpServletRequest request, Map params) {InputStream is = null; try {DiskFileItemFactory factory = new DiskFileItemFactory (); ServletFileUpload upload = new ServletFileUpload (factory); / / set the file size limit to 10m factory.setSizeThreshold (1024 * 1024) List items = upload.parseRequest (request); Iterator iter = items.iterator (); while (iter.hasNext ()) {FileItem item = (FileItem) iter.next (); if (! item.isFormField ()) {/ / get the input stream is = item.getInputStream () of the uploaded file } else {String paramName = item.getFieldName (); String paramValue = item.getString (); paramValue = new String (paramValue.getBytes ("ISO-8859-1"), "UTF-8"); params.put (paramName, paramValue) } catch (FileUploadException e) {e.printStackTrace ();} catch (UnsupportedEncodingException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace ();} return is }} user information operation code: user information operation: public class UserServlet extends BaseBackServlet {@ Override public String add (HttpServletRequest request, HttpServletResponse response, Page page) {System.out.println ("UserServlet add method called"); return null;} @ Override public String delete (HttpServletRequest request, HttpServletResponse response, Page page) {System.out.println ("UserServlet delete method called") Int id = Integer.parseInt (request.getParameter ("id")); userDAO.delete (id); return "@ admin_user_list";} @ Override public String update (HttpServletRequest request, HttpServletResponse response, Page page) {System.out.println ("UserServlet update method called"); Map params = new HashMap (); InputStream is = super.parseUpload (request, params); System.out.println (params) Int id = Integer.parseInt (params.get ("id")); String password = params.get ("password"); User user = userDAO.get (id); user.setPassword (password); userDAO.update (user); return "@ admin_user_list";} @ Override public String edit (HttpServletRequest request, HttpServletResponse response, Page page) {System.out.println ("UserServlet edit method called") Int id = Integer.parseInt (request.getParameter ("id")); User u = userDAO.get (id); request.setAttribute ("u", u); return "admin/editUser.jsp";} @ Override public String list (HttpServletRequest request, HttpServletResponse response, Page page) {System.out.println ("UserServlet list method called"); List us = userDAO.list (page.getStart (), page.getCount ()) Int total = userDAO.getTotal (); page.setTotal (total); request.setAttribute ("us", us); request.setAttribute ("page", page); return "admin/listUser.jsp";}} these are all the contents of the article "how Java can imitate Tmall online Mall". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Module method information user article project management mall online mall Tmall code content commodity foundation file order classification not much front desk function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Redmi vpn Huawei