博客目录
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")publicclassOrderFormDaoImplimplementsOrderFormDao{//使用spring对Hibernate的模版 HibernateTemplate@Resource(name="hibernateTemplate")private HibernateTemplate hibernateTemplate;publicvoiddelete(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;}publicvoidsave(OrderForm orderForm){
- System.out.println(orderForm);
- hibernateTemplate.save(orderForm);}publicvoidupdate(OrderForm orderForm){
- hibernateTemplate.update(orderForm);}public HibernateTemplate getHibernateTmeplate(){return hibernateTemplate;}publicvoidsetHibernateTmeplate(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")publicclassAdminDaoImplimplementsAdminDao{//使用spring对Hibernate的模版 HibernateTemplate@Resource(name="hibernateTemplate")private HibernateTemplate hibernateTemplate;publicvoiddelete(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;}publicvoidsave(Admin admin){
- System.out.println(admin);
- hibernateTemplate.save(admin);}publicvoidupdate(Admin admin){
- hibernateTemplate.update(admin);}public HibernateTemplate getHibernateTmeplate(){return hibernateTemplate;}publicvoidsetHibernateTmeplate(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")publicclassOrderFormServiceImplimplementsOrderFormService{//要调用dao层代码,所以要有OrderFormDao的对象,把其实现类靠spring注入@Resource(name="orderFormDaoImpl")private OrderFormDao orderFormDao;public OrderFormDao getOrderFormDao(){return orderFormDao;}publicvoidsetOrderFormDao(OrderFormDao orderFormDao){this.orderFormDao = orderFormDao;}publicvoiddelete(OrderForm orderForm){this.orderFormDao.delete(orderForm);}public List<OrderForm>findAllOrderForms(){returnthis.orderFormDao.findAllOrderForms();}public OrderForm findOrderFormById(int id){returnthis.orderFormDao.findOrderFormById(id);}publicvoidsave(OrderForm orderForm){this.orderFormDao.save(orderForm);}publicvoidupdate(OrderForm orderForm){this.orderFormDao.update(orderForm);}public OrderForm queryOrderForm(int orderFormId){returnthis.orderFormDao.queryOrderForm(orderFormId);}public List<OrderForm>findOrderFormByUserName(String username){returnthis.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")publicclassAdminServiceImplimplementsAdminService{//要调用dao层代码,所以要有UserDao的对象,把其实现类靠spring注入@Resource(name="adminDaoImpl")private AdminDao adminDao;public AdminDao getUserDao(){return adminDao;}publicvoidsetUserDao(AdminDao adminDao){this.adminDao = adminDao;}publicvoiddelete(Admin user){this.adminDao.delete(user);}public List<Admin>findAllAdmins(){returnthis.adminDao.findAllAdmins();}public Admin findAdminById(int id){// TODO Auto-generated method stubreturnthis.adminDao.findAdminById(id);}publicvoidsave(Admin admin){this.adminDao.save(admin);}publicvoidupdate(Admin admin){this.adminDao.update(admin);}public Admin getUserByLoginNameAndPassword(String name, String password){returnthis.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")//多例,每个恳求生成一个新的actionpublicclassOrderFormActionextendsActionSupport{private OrderForm orderForm;//要调用OrderFormService的方法,所以要声明,让spring把其实现类注入@Resource(name="orderFormServiceImpl")
- OrderFormService service;private UserService userservice;public OrderFormService getService(){return service;}publicvoidsetService(OrderFormService service){this.service = service;}public OrderForm getOrderForm(){return orderForm;}publicvoidsetOrderForm(OrderForm orderForm){this.orderForm = orderForm;}@ResourcepublicvoidsetUserservice(UserService userservice){this.userservice = userservice;}public UserService getUserservice(){return userservice;}@Overridepublic 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")//多例,每个恳求生成一个新的actionpublicclassAdminActionextendsActionSupport{private Admin admin;//private Role role;//private Department department;//要调用UserService的方法,所以要声明,让spring把其实现类注入@Resource(name="adminServiceImpl")
- AdminService service;public AdminService getService(){return service;}publicvoidsetService(AdminService service){this.service = service;}public Admin getAdmin(){return admin;}publicvoidsetAdmin(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(){//adminpassmessagethis.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)
最后,别忘了一键三连哦 |