Java项目:JSP药店药品商城管理系统
作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目分为前后台,分为管理员与普通用户两种角色,管理员登录后台,普通用户登录前台;
管理员角色包含以下功能:
管理员登录,订单管理,客户管理,药品管理,类目管理等功能。
用户角色包含以下功能:
用户首页,查看药品详情,用户登录,查看购物车,提交订单付款,我的订单管理,用户个人中心等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;
技术栈
JSP+CSS+jQuery+bootstrap+mysql+servlet
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中src/utils/DBUtil.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/jsp_medi/ 登录 注:tomcat中配置项目路径必须为jsp_medi,否则会有异常;
用户账号/密码:user/123456
管理员账号/密码:admin/admin
运行截图
前台界面

后台界面

相关代码
ApplicationListener
package listener;import service.TypeService;import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionBindingEvent;@WebListener()
public class ApplicationListener implements ServletContextListener,HttpSessionListener, HttpSessionAttributeListener {TypeService tsService=new TypeService();// Public constructor is required by servlet specpublic ApplicationListener() {}// -------------------------------------------------------// ServletContextListener implementation// -------------------------------------------------------public void contextInitialized(ServletContextEvent sce) {/* This method is called when the servlet context isinitialized(when the Web application is deployed). You can initialize servlet context related data here.*/sce.getServletContext().setAttribute("typeList",tsService.GetAllType());}public void contextDestroyed(ServletContextEvent sce) {/* This method is invoked when the Servlet Context (the Web application) is undeployed or Application Server shuts down.*/}// -------------------------------------------------------// HttpSessionListener implementation// -------------------------------------------------------public void sessionCreated(HttpSessionEvent se) {/* Session is created. */}public void sessionDestroyed(HttpSessionEvent se) {/* Session is destroyed. */}// -------------------------------------------------------// HttpSessionAttributeListener implementation// -------------------------------------------------------public void attributeAdded(HttpSessionBindingEvent sbe) {/* This method is called when an attribute is added to a session.*/}public void attributeRemoved(HttpSessionBindingEvent sbe) {/* This method is called when an attributeis removed from a session.*/}public void attributeReplaced(HttpSessionBindingEvent sbe) {/* This method is invoked when an attibuteis replaced in a session.*/}
}
GoodsService
package service;import dao.GoodsDao;
import model.Goods;
import model.Page;
import sun.nio.cs.ext.IBM037;import javax.management.monitor.StringMonitorMBean;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;public class GoodsService {private GoodsDao gDao=new GoodsDao();public List
OrderService
package service;import dao.*;
import model.*;
import utils.*;import java.sql.*;
import java.util.List;public class OrderService {private OrderDao oDao = new OrderDao();public void addOrder(Order order) {Connection con = null;try {con = DBUtil.getConnection();con.setAutoCommit(false);oDao.insertOrder(con, order);int id = oDao.getLastInsertId(con);order.setId(id);for(OrderItem item : order.getItemMap().values()) {oDao.insertOrderItem(con, item);}con.commit();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();if(con!=null)try {con.rollback();} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}}public List selectAll(int userid){List list=null;try {list = oDao.selectAll(userid);for(Order o :list) {List l = oDao.selectAllItem(o.getId());o.setItemList(l);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}public Page getOrderPage(int status,int pageNumber) {Page p = new Page();p.setPageNumber(pageNumber);int pageSize = 10;int totalCount = 0;try {totalCount = oDao.getOrderCount(status);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}p.SetPageSizeAndTotalCount(pageSize, totalCount);List list=null;try {list = oDao.selectOrderList(status, pageNumber, pageSize);for(Order o :(List)list) {List l = oDao.selectAllItem(o.getId());o.setItemList(l);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}p.setList(list);return p;}public void updateStatus(int id,int status) {try {oDao.updateStatus(id, status);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void delete(int id) {Connection con = null;try {con = DBUtil.getDataSource().getConnection();con.setAutoCommit(false);oDao.deleteOrderItem(con, id);oDao.deleteOrder(con, id);con.commit();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();if(con!=null)try {con.rollback();} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}}
}
TypeService
package service;import dao.TypeDao;
import model.Type;import java.sql.SQLException;
import java.util.List;public class TypeService {TypeDao tDao=new TypeDao();public List GetAllType(){List list=null;try {list=tDao.GetAllType();} catch (SQLException e) {e.printStackTrace();}return list;}public Type selectTypeNameByID(int typeid){Type type=null;try {type=tDao.selectTypeNameByID(typeid);} catch (SQLException e) {e.printStackTrace();}return type;}public Type select(int id) {Type t=null;try {t = tDao.select(id);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return t;}public void insert(Type t) {try {tDao.insert(t);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void update(Type t) {try {tDao.update(t);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public boolean delete(int id) {try {tDao.delete(id);return true;} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();return false;}}
}
UserService
package service;import dao.UserDao;
import model.Page;
import model.User;import java.sql.SQLException;
import java.util.List;public class UserService {private UserDao uDao = new UserDao();public boolean register(User user) {try {if(uDao.isUsernameExist(user.getUsername())) {return false;}if(uDao.isEmailExist(user.getEmail())) {return false;}uDao.addUser(user);return true;} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return false;}public User login(String ue,String password) {User user=null;try {user = uDao.selectByUsernamePassword(ue, password);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}if(user!=null) {return user;}try {user=uDao.selectByEmailPassword(ue, password);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}if(user!=null) {return user;}return null;}public User selectById(int id) {User u=null;try {u = uDao.selectById(id);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return u;}public void updateUserAddress(User user) {try {uDao.updateUserAddress(user);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void updatePwd(User user) {try {uDao.updatePwd(user);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public Page getUserPage(int pageNumber) {Page p = new Page();p.setPageNumber(pageNumber);int pageSize = 7;int totalCount = 0;try {totalCount = uDao.selectUserCount();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}p.SetPageSizeAndTotalCount(pageSize, totalCount);List list=null;try {list = uDao.selectUserList( pageNumber, pageSize);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}p.setList(list);return p;}public boolean delete(int id ) {try {uDao.delete(id);return true;} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();return false;}}
}
如果也想学习本系统,下面领取。关注并回复:070jsp
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
