Java 实战项目锤炼之仿天猫网上商城的实现流程

网友投稿 255 2022-11-23

Java 实战项目锤炼之仿天猫网上商城的实现流程

一、项目简述

功能:

前台:

* 用户模块

* 分类模块

* 商品模块

* 购物车模块

* 订单模块

后台:

* 管理员模块

* 分类管理模块

* 商品管理模块

* 订单模块

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: jsP + C3P0+ Servlert + html+ css + javascript + jquery + Ajax + Fileupload等等。

基础信息操作代码:

基础信息操作:

public abstract class BaseBackServlet extends HttpServlet {

http://

/* 添加 */

public abstract String add(HttpServletRequest request, HttpServletResponse response, Page page);

/* 删除 */

public abstract String delete(HttpServletRequest request, HttpServletResponse response, Page page);

/* 更新 */

public abstract String update(HttpServletRequest request, HttpServletResponse response, Page page);

/* 修改 */

public abstract String edit(HttpServletRequest request, HttpServletResponse response, Page page);

/* 显示 */

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{

/* 获取分页信息 */

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);

/* 借助反射,调用对应的方法 */

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();

/* 根据方法的返回值,进行相应的客户端、服务端跳转,或仅输出字符串 */

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 parseUphttp://load(HttpServletRequest request, Map params){

InputStream is = null;

try{

DiskFileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);

//设置上传的文件大小限制为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()){

//获取上传文件的输入流

is = item.getInputStream();

} 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;

}

}

用户信息操作代码:

用户信息操作:

public class UserServlet extends BaseBackServlet {

@Override

public String add(HttpServletRequest request, HttpServletResponse response, Page page) {

System.out.println("调用了 UserServlet add方法");

return null;

}

@Override

public String delete(HttpServletRequest request, HttpServletResponse response, Page page) {

System.out.println("调用了 UserServlet delete方法");

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方法");

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);

MCfhNIKdJzreturn "@admin_user_list";

}

@Override

public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {

System.out.println("调用了 UserServlet edit方法");

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方法");

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";

}

}

以上就是java 实战项目锤炼之仿天猫网上商城的实现流程的详细内容,更多关于Java 天猫商城的资料请关注我们其它相关文章!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:2020年将会有一半的智能手机实现Type-C互联
下一篇:浅析大数据框架 Hadoop~
相关文章

 发表评论

暂时没有评论,来抢沙发吧~