Jsp+SSH+mysql实现的web网上商场系统(前台/后台 功能:商品管理、购物车管理、订单管理、用户管理)

SSH-WEB商场系统

本系统是一套电商管理的系统,方便人们在线购买商品,方便商家后台管理自己的商品。

实现功能截图

功能点:
(1) 登录功能:用户输入用户名和密码,进行登录验证。
(2) 注册功能:可以查询用户名是否已经存在,对注册信息进行验证。
(3) 商品浏览:可以查询商品,显示商品详情,提供购买链接。
(4) 购物车管理:欲购买商品可以增添到购物车,也可以从购物车删除商品。
(5) 订单查询:用户登录后可以下订单,用户登录后也可以查看自己的订单。
(6) 商品种类管理:管理员可以对商品种类进行添加、删除操作。
(7) 商品管理:管理员可以添加商品、删除商品,查看所有商品。
(8) 订单管理:管理员登录后可以对订单进行管理。
(9) 用户管理:管理员可以管理注册用户信息。

前台:

用户注册登录:
在这里插入图片描述
在这里插入图片描述

首页:
在这里插入图片描述
商品分类浏览:
在这里插入图片描述
商品详情:
在这里插入图片描述
购物车:
在这里插入图片描述
我的订单:
在这里插入图片描述
个人信息更新:
在这里插入图片描述
后台:

管理员登录:
在这里插入图片描述
商品种类列表:
在这里插入图片描述
新增种类:
在这里插入图片描述
商品列表:
在这里插入图片描述
添加商品:
在这里插入图片描述
订单管理:
在这里插入图片描述
用户管理:
在这里插入图片描述
管理员密码修改:
在这里插入图片描述

主要流程图

1、系统功能流程图:
在这里插入图片描述
在这里插入图片描述

2、数据流图:
顶层数据流图:
在这里插入图片描述
用户管理数据流图:
在这里插入图片描述
商品管理数据流图:
在这里插入图片描述
3、数据字典
关键数据项:
在这里插入图片描述

技术点总结

java框架:SSH
jdk版本:1.7
tomcat: 7.0
数据库:mysql
开发工具:myeclipse

代码

dao层:
订单Dao:OrderDaoImpl.java

package cn.itbaizhan.dao.impl;

import java.util.List;

import javax.annotation.Resource;




import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import cn.itbaizhan.dao.OrderFormDao;
import cn.itbaizhan.po.Commodity;
import cn.itbaizhan.po.OrderForm;
import cn.itbaizhan.po.User;
@Component("orderFormDaoImpl")
public class OrderFormDaoImpl implements OrderFormDao {
//使用spring对Hibernate的模版 HibernateTemplate
	@Resource(name="hibernateTemplate")
	private HibernateTemplate hibernateTemplate;
	
	public void delete(OrderForm orderForm) {
	hibernateTemplate.delete(orderForm);
	}
	@SuppressWarnings("unchecked")
	public List<OrderForm> findAllOrderForms() {
		String hql = "from OrderForm";
		return (List<OrderForm>)hibernateTemplate.find(hql);
	}

	public OrderForm findOrderFormById(int id) {
		OrderForm orderForm = (OrderForm)hibernateTemplate.get(OrderForm.class, id);
		return orderForm;
	}

	public void save(OrderForm orderForm) {
		System.out.println(orderForm);
	 hibernateTemplate.save(orderForm);
	}

	public void update(OrderForm orderForm) {
	hibernateTemplate.update(orderForm);

	}
	public HibernateTemplate getHibernateTmeplate() {
		return hibernateTemplate;
	}
	public void setHibernateTmeplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	public OrderForm queryOrderForm(int orderFormId) {
		
		return (OrderForm)hibernateTemplate.getSessionFactory().openSession().createQuery(
		"from OrderForm o where o.orderFormId=? ").setParameter(
				0, orderFormId).uniqueResult();

	}
	@SuppressWarnings("unchecked")
	public List<OrderForm> findOrderFormByUserName(String username) {
		System.out.println("用户名:"+username);
		String hql = "from OrderForm o where o.username=?";
		
		return (List<OrderForm>)hibernateTemplate.find(hql,username);
	}
	
}

AdminDaoImpl.java:

package cn.itbaizhan.dao.impl;

import java.util.List;

import javax.annotation.Resource;




import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import cn.itbaizhan.dao.AdminDao;
import cn.itbaizhan.po.Admin;
@Component("adminDaoImpl")
public class AdminDaoImpl implements AdminDao {
//使用spring对Hibernate的模版 HibernateTemplate
	@Resource(name="hibernateTemplate")
	private HibernateTemplate hibernateTemplate;
	
	public void delete(Admin admin) {
	hibernateTemplate.delete(admin);
	}
	@SuppressWarnings("unchecked")
	public List<Admin> findAllAdmins() {
		String hql = "from Admin";
		return (List<Admin>)hibernateTemplate.find(hql);
	}

	public Admin findAdminById(int id) {
		Admin admin = (Admin)hibernateTemplate.get(Admin.class, id);
		return admin;
	}

	public void save(Admin admin) {
		System.out.println(admin);
	 hibernateTemplate.save(admin);
	}

	public void update(Admin admin) {
	hibernateTemplate.update(admin);

	}
	public HibernateTemplate getHibernateTmeplate() {
		return hibernateTemplate;
	}
	public void setHibernateTmeplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	
	//获取用户
	public Admin getUserByLoginNameAndPassword(String username, String password) {
		//String[] values={username, password}; 
		//String hql = "from User u where u.username=? and u.password=?";
		//(List<User>)hibernateTemplate.find(hql, values);
		System.out.println("用户名:"+username);
		
		return  (Admin) hibernateTemplate.getSessionFactory().openSession().createQuery(
		"from Admin a where a.username=? and a.password=?").setParameter(0, username).setParameter(1, password).uniqueResult();
	}

	

}

业务逻辑层(service)
订单业务逻辑层:OrderServiceImpl.java

package cn.itbaizhan.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.itbaizhan.dao.OrderFormDao;
import cn.itbaizhan.po.OrderForm;
import cn.itbaizhan.po.User;
import cn.itbaizhan.service.OrderFormService;
//把类交给spring管理(如同配置bean节点)此类受spring事务管理
@Component("orderFormServiceImpl")
public class OrderFormServiceImpl implements OrderFormService {
	//要调用dao层代码,所以要有OrderFormDao的对象,把其实现类靠spring注入
	@Resource(name="orderFormDaoImpl")
	private OrderFormDao orderFormDao;
	public OrderFormDao getOrderFormDao() {
		return orderFormDao;
	}

	public void setOrderFormDao(OrderFormDao orderFormDao) {
		this.orderFormDao = orderFormDao;
	}

	public void delete(OrderForm orderForm) {
		this.orderFormDao.delete(orderForm);

	}
	public List<OrderForm> findAllOrderForms() {
		return this.orderFormDao.findAllOrderForms();
	}
	public OrderForm findOrderFormById(int id) {
		
		return this.orderFormDao.findOrderFormById(id);
	}

	public void save(OrderForm orderForm) {
		this.orderFormDao.save(orderForm);

	}

	public void update(OrderForm orderForm) {
		this.orderFormDao.update(orderForm);
	}

	public OrderForm queryOrderForm(int orderFormId) {
		
		return this.orderFormDao.queryOrderForm(orderFormId);
	}

	public List<OrderForm> findOrderFormByUserName(String username) {
		
		return this.orderFormDao.findOrderFormByUserName(username);
	}

	


}

管理员业务逻辑层:AdminServiceImpl.java

package cn.itbaizhan.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.itbaizhan.dao.AdminDao;
import cn.itbaizhan.po.Admin;
import cn.itbaizhan.service.AdminService;
//把类交给spring管理(如同配置bean节点)此类受spring事务管理
@Component("adminServiceImpl")
public class AdminServiceImpl implements AdminService {
	//要调用dao层代码,所以要有UserDao的对象,把其实现类靠spring注入
	@Resource(name="adminDaoImpl")
	private AdminDao adminDao;
	public AdminDao getUserDao() {
		return adminDao;
	}

	public void setUserDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}

	public void delete(Admin user) {
		this.adminDao.delete(user);

	}
	public List<Admin> findAllAdmins() {
		return this.adminDao.findAllAdmins();
	}
	public Admin findAdminById(int id) {
		// TODO Auto-generated method stub
		return this.adminDao.findAdminById(id);
	}

	public void save(Admin admin) {
		this.adminDao.save(admin);

	}

	public void update(Admin admin) {
		this.adminDao.update(admin);
	}


	public Admin getUserByLoginNameAndPassword(String name, String password) {
		
		return this.adminDao.getUserByLoginNameAndPassword(name,password);
	}


}

action层:
订单action:OrderAction.java

package cn.itbaizhan.action;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cn.itbaizhan.action.*;
import cn.itbaizhan.po.Commodity;
import cn.itbaizhan.po.OrderForm;
import cn.itbaizhan.po.User;
import cn.itbaizhan.service.OrderFormService;
import cn.itbaizhan.service.UserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
@Component("orderFormAction")
@Scope("prototype")//多例,每个请求生成一个新的action
public class OrderFormAction extends ActionSupport {
	private OrderForm orderForm;
	
//要调用OrderFormService的方法,所以要声明,让spring把其实现类注入
	@Resource(name="orderFormServiceImpl")
	OrderFormService service;
	
	private UserService userservice;
	
	public OrderFormService getService() {
		return service;
	}

	public void setService(OrderFormService service) {
		this.service = service;
	}

	public OrderForm getOrderForm() {
		return orderForm;
	}

	public void setOrderForm(OrderForm orderForm) {
		this.orderForm = orderForm;
	}
	

	@Resource
	public void setUserservice(UserService userservice) {
		this.userservice = userservice;
	}


	public UserService getUserservice() {
		return userservice;
	}

	@Override
	public String execute() throws Exception {
		// 不要直接访问数据库,应该访问业务逻辑层service,而service去访问DAO,DAO去访问数据库
			this.service.save(this.orderForm);
			System.out.println("orderForm:"+orderForm.getUsername());
			ActionContext.getContext().put("ordermessage", "您的订单已经提交!");
			return "success";
	}
	//列表
	@SuppressWarnings("unchecked")
	public String listOrderForm(){
		Map request = (Map) ActionContext.getContext().get("request");
		
		request.put("listOrderForms", service.findAllOrderForms());
		System.out.println("listOrderForms");
		return "listOrderForm";
	}
	//查询
	@SuppressWarnings("unchecked")
	public String queryOrderForm(){
		int orderFormId= orderForm.getOrderFormId();
		System.out.println("orderFormId:"+orderFormId);
		String username= orderForm.getUsername();
		System.out.println("username:"+username);
		String submitTime= orderForm.getSubmitTime();
		System.out.println("submitTime:"+submitTime);
		String consignmentTime= orderForm.getConsignmentTime();
		System.out.println("consignmentTime:"+consignmentTime);
	
		OrderForm orderForm=this.service.queryOrderForm(orderFormId);
		Map request=(Map) ActionContext.getContext().get("request");
		
		request.put("queryOrder", orderForm);
		return "queryOrder";
	}
	

	public String deleteOrderForm(){
		this.service.delete(orderForm);
		return "deleteOrderForm";
	}
	public String findOrderFormById(){
		orderForm = this.service.findOrderFormById(orderForm.getOrderFormId());
		return "findOrderForm";
	}
	//付款
	@SuppressWarnings("unchecked")
	public String payOrderForm(){
		double totalprice=orderForm.getTotalPrice();//订单总金额
		User user=userservice.findUserByName(orderForm.getUsername());
		double money=user.getMoney();//用户所有金钱
		Map request = (Map) ActionContext.getContext().get("request");
		if(totalprice>money){		
			request.put("nowOrder", orderForm);
			ActionContext.getContext().put("payemessage", "您的金额不足!");
		}
		else
		{
		user.setMoney(money-totalprice);
		userservice.update(user);
		orderForm.setIsPayoff("是");
		this.service.update(orderForm);
		
		System.out.println("orderForm:"+orderForm.getOrderFormId());
		
		request.put("nowOrder", orderForm);
		ActionContext.getContext().put("payemessage", "付款成功!");
		}
		return "payOrderForm";
	}
	
	//订单列表付款
	@SuppressWarnings("unchecked")
	public String payOrder(){
		double totalprice=orderForm.getTotalPrice();//订单总金额
		String username=orderForm.getUsername();
		User user=userservice.findUserByName(orderForm.getUsername());
		double money=user.getMoney();//用户所有金钱
		
		Map request = (Map) ActionContext.getContext().get("request");
		
		if(totalprice>money){
	
			request.put("orderFormByUserName", service.findOrderFormByUserName(username));
			ActionContext.getContext().put("payemessage", "您的金额不足!");
		}
		else
		{
		user.setMoney(money-totalprice);
		userservice.update(user);
		orderForm.setIsPayoff("是");
		this.service.update(orderForm);
		System.out.println("orderForm:"+orderForm.getOrderFormId());
		
		request.put("orderFormByUserName", service.findOrderFormByUserName(username));
		ActionContext.getContext().put("payemessage", "付款成功!");
		}
		return "payOrder";
	}
	
	public String inputOrderForm(){
		return "input";
	}
	//发货
	@SuppressWarnings("unchecked")
	public String conOrder(){
		orderForm.setIsConsignment("是");
		this.service.update(orderForm);
		Map request = (Map) ActionContext.getContext().get("request");
		request.put("listOrderForms", service.findAllOrderForms());
		
		return "conOrder";
	}
	//提交订单
	@SuppressWarnings("unchecked")
	public String addOrderForm(){
		this.service.save(this.orderForm);
		
		Map session = ActionContext.getContext().getSession();//获得session对象
		List<Commodity> car = (List<Commodity>)session.get("car");//取得购物车
		car.clear();
		
		Map request = (Map) ActionContext.getContext().get("request");
		request.put("nowOrder",orderForm);
		return "addOrderForm";
	}
	
	@SuppressWarnings("unchecked")
	public String findOrderFormByUserName(){
		Map request = (Map) ActionContext.getContext().get("request");
		
		request.put("orderFormByUserName",this.service.findOrderFormByUserName(orderForm.getUsername()));
		return "findOrderFormByUserName";
	}
	
}

管理员action:AdminAction.java

package cn.itbaizhan.action;

import java.util.Collection;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cn.itbaizhan.po.Admin;
import cn.itbaizhan.service.AdminService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;



@SuppressWarnings("serial")
@Component("adminAction")
@Scope("prototype")//多例,每个请求生成一个新的action
public class AdminAction extends ActionSupport {
	private Admin admin;
	
	//private Role role;
	//private Department department;
//要调用UserService的方法,所以要声明,让spring把其实现类注入
	@Resource(name="adminServiceImpl")
	AdminService service;
	public AdminService getService() {
		return service;
	}

	public void setService(AdminService service) {
		this.service = service;
	}

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}
	
	@SuppressWarnings("unchecked")
	public String listAdmin(){
		Map request = (Map) ActionContext.getContext().get("request");
		
		request.put("list", service.findAllAdmins());
		return "listAdmin";
	}
	public String deleteAdmin(){
		this.service.delete(admin);
		return "deleteAdmin";
	}
	public String findAdminById(){
		admin = this.service.findAdminById(admin.getAdminId());
		return "findAdmin";
	}
	public String updateAdmin(){
		//adminpassmessage
		
		this.service.update(admin);
		System.out.println("admin:"+admin.getUsername());
		ActionContext.getContext().put("upAdminMessage", "密码修改成功!");	
		return "updateAdmin";
		
	}
	public String inputAdmin(){
		return "input";
	}
	
	@SuppressWarnings("unchecked")
	public String addAdmin(){
		Map request = (Map) ActionContext.getContext().get("request");
		
		return "addAdmin";
	}

	//管理员登录
	public String login(){
		String username= admin.getUsername();
		System.out.println(username);
		String password=admin.getPassword();

		Admin admin = service.getUserByLoginNameAndPassword(username,password);
		System.out.print("name:"+username+",pass:"+password+",user:"+admin);
		if(admin == null){
			ActionContext.getContext().put("message", "用户名或密码错误");		
			return "login";
		}else{
			ActionContext.getContext().getSession().put("admin", admin);
			return "index";
		}
	}
	//退出
	public String logout(){
		ActionContext.getContext().getSession().clear();
		return "logout";
	}
}

写在最后

码代码不容易,需要的同学可以参考学习,全部代码不能都贴出,如果需要可以+博主V交流获取(Code2Life2)
最后,别忘了一键三连哦

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页