• Java项目:JSP药店药品商城管理系统


    作者主页:源码空间站2022

     简介: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

    1. package listener;
    2. import service.TypeService;
    3. import javax.servlet.ServletContextEvent;
    4. import javax.servlet.ServletContextListener;
    5. import javax.servlet.annotation.WebListener;
    6. import javax.servlet.http.HttpSessionAttributeListener;
    7. import javax.servlet.http.HttpSessionEvent;
    8. import javax.servlet.http.HttpSessionListener;
    9. import javax.servlet.http.HttpSessionBindingEvent;
    10. @WebListener()
    11. public class ApplicationListener implements ServletContextListener,
    12. HttpSessionListener, HttpSessionAttributeListener {
    13. TypeService tsService=new TypeService();
    14. // Public constructor is required by servlet spec
    15. public ApplicationListener() {
    16. }
    17. // -------------------------------------------------------
    18. // ServletContextListener implementation
    19. // -------------------------------------------------------
    20. public void contextInitialized(ServletContextEvent sce) {
    21. /* This method is called when the servlet context is
    22. initialized(when the Web application is deployed).
    23. You can initialize servlet context related data here.
    24. */
    25. sce.getServletContext().setAttribute("typeList",tsService.GetAllType());
    26. }
    27. public void contextDestroyed(ServletContextEvent sce) {
    28. /* This method is invoked when the Servlet Context
    29. (the Web application) is undeployed or
    30. Application Server shuts down.
    31. */
    32. }
    33. // -------------------------------------------------------
    34. // HttpSessionListener implementation
    35. // -------------------------------------------------------
    36. public void sessionCreated(HttpSessionEvent se) {
    37. /* Session is created. */
    38. }
    39. public void sessionDestroyed(HttpSessionEvent se) {
    40. /* Session is destroyed. */
    41. }
    42. // -------------------------------------------------------
    43. // HttpSessionAttributeListener implementation
    44. // -------------------------------------------------------
    45. public void attributeAdded(HttpSessionBindingEvent sbe) {
    46. /* This method is called when an attribute
    47. is added to a session.
    48. */
    49. }
    50. public void attributeRemoved(HttpSessionBindingEvent sbe) {
    51. /* This method is called when an attribute
    52. is removed from a session.
    53. */
    54. }
    55. public void attributeReplaced(HttpSessionBindingEvent sbe) {
    56. /* This method is invoked when an attibute
    57. is replaced in a session.
    58. */
    59. }
    60. }

    GoodsService

    1. package service;
    2. import dao.GoodsDao;
    3. import model.Goods;
    4. import model.Page;
    5. import sun.nio.cs.ext.IBM037;
    6. import javax.management.monitor.StringMonitorMBean;
    7. import java.sql.SQLException;
    8. import java.util.List;
    9. import java.util.Map;
    10. public class GoodsService {
    11. private GoodsDao gDao=new GoodsDao();
    12. public List> getGoodsList(int recommendType) {
    13. List> list=null;
    14. try {
    15. list=gDao.getGoodsList(recommendType);
    16. } catch (SQLException e) {
    17. e.printStackTrace();
    18. }
    19. return list;
    20. }
    21. public Map getScrollGood()
    22. {
    23. Map scroolGood=null;
    24. try {
    25. scroolGood=gDao.getScrollGood();
    26. } catch (SQLException e) {
    27. e.printStackTrace();
    28. }
    29. return scroolGood;
    30. }
    31. public List selectGoodsByTypeID(int typeID, int pageNumber, int pageSize)
    32. {
    33. List list=null;
    34. try {
    35. list=gDao.selectGoodsByTypeID(typeID,pageNumber,pageSize);
    36. } catch (SQLException e) {
    37. e.printStackTrace();
    38. }
    39. return list;
    40. }
    41. public Page selectPageByTypeID(int typeID,int pageNumber)
    42. {
    43. Page p=new Page();
    44. p.setPageNumber(pageNumber);
    45. int totalCount=0;
    46. try {
    47. totalCount=gDao.getCountOfGoodsByTypeID(typeID);
    48. } catch (SQLException e) {
    49. e.printStackTrace();
    50. }
    51. p.SetPageSizeAndTotalCount(8,totalCount);
    52. List list=null;
    53. try {
    54. list=gDao.selectGoodsByTypeID(typeID,pageNumber,8);
    55. } catch (SQLException e) {
    56. e.printStackTrace();
    57. }
    58. p.setList(list);
    59. return p;
    60. }
    61. public Page getGoodsRecommendPage(int type,int pageNumber) {
    62. Page p = new Page();
    63. p.setPageNumber(pageNumber);
    64. int totalCount = 0;
    65. try {
    66. totalCount = gDao.getRecommendCountOfGoodsByTypeID(type);
    67. } catch (SQLException e) {
    68. // TODO Auto-generated catch block
    69. e.printStackTrace();
    70. }
    71. p.SetPageSizeAndTotalCount(8, totalCount);
    72. List list=null;
    73. try {
    74. list = gDao.selectGoodsbyRecommend(type, pageNumber, 8);
    75. for(Goods g : (List)list) {
    76. g.setScroll(gDao.isScroll(g));
    77. g.setHot(gDao.isHot(g));
    78. g.setNew(gDao.isNew(g));
    79. }
    80. } catch (SQLException e) {
    81. // TODO Auto-generated catch block
    82. e.printStackTrace();
    83. }
    84. p.setList(list);
    85. return p;
    86. }
    87. public Goods getGoodsById(int id) {
    88. Goods g=null;
    89. try {
    90. g = gDao.getGoodsById(id);
    91. } catch (SQLException e) {
    92. // TODO Auto-generated catch block
    93. e.printStackTrace();
    94. }
    95. return g;
    96. }
    97. public Page getSearchGoodsPage(String keyword, int pageNumber) {
    98. Page p = new Page();
    99. p.setPageNumber(pageNumber);
    100. int totalCount = 0;
    101. try {
    102. // totalCount = gDao.getGoodsCount(typeId);
    103. totalCount = gDao.getSearchCount(keyword);
    104. } catch (SQLException e) {
    105. // TODO Auto-generated catch block
    106. e.printStackTrace();
    107. }
    108. p.SetPageSizeAndTotalCount(8, totalCount);
    109. List list=null;
    110. try {
    111. // list = gDao.selectGoods(keyword, pageNo, 8);
    112. list = gDao.selectSearchGoods(keyword,pageNumber,8);
    113. } catch (SQLException e) {
    114. // TODO Auto-generated catch block
    115. e.printStackTrace();
    116. }
    117. p.setList(list);
    118. return p;
    119. }
    120. public void addRecommend(int id,int type) {
    121. try {
    122. gDao.addRecommend(id, type);
    123. } catch (SQLException e) {
    124. // TODO Auto-generated catch block
    125. e.printStackTrace();
    126. }
    127. }
    128. public void removeRecommend(int id,int type) {
    129. try {
    130. gDao.removeRecommend(id, type);
    131. } catch (SQLException e) {
    132. // TODO Auto-generated catch block
    133. e.printStackTrace();
    134. }
    135. }
    136. public void insert(Goods goods) {
    137. try {
    138. gDao.insert(goods);
    139. } catch (SQLException e) {
    140. // TODO Auto-generated catch block
    141. e.printStackTrace();
    142. }
    143. }
    144. public void update(Goods goods) {
    145. try {
    146. gDao.update(goods);
    147. } catch (SQLException e) {
    148. // TODO Auto-generated catch block
    149. e.printStackTrace();
    150. }
    151. }
    152. public void delete(int id) {
    153. try {
    154. gDao.delete(id);
    155. } catch (SQLException e) {
    156. // TODO Auto-generated catch block
    157. e.printStackTrace();
    158. }
    159. }
    160. }

    OrderService

    1. package service;
    2. import dao.*;
    3. import model.*;
    4. import utils.*;
    5. import java.sql.*;
    6. import java.util.List;
    7. public class OrderService {
    8. private OrderDao oDao = new OrderDao();
    9. public void addOrder(Order order) {
    10. Connection con = null;
    11. try {
    12. con = DBUtil.getConnection();
    13. con.setAutoCommit(false);
    14. oDao.insertOrder(con, order);
    15. int id = oDao.getLastInsertId(con);
    16. order.setId(id);
    17. for(OrderItem item : order.getItemMap().values()) {
    18. oDao.insertOrderItem(con, item);
    19. }
    20. con.commit();
    21. } catch (SQLException e) {
    22. // TODO Auto-generated catch block
    23. e.printStackTrace();
    24. if(con!=null)
    25. try {
    26. con.rollback();
    27. } catch (SQLException e1) {
    28. // TODO Auto-generated catch block
    29. e1.printStackTrace();
    30. }
    31. }
    32. }
    33. public List selectAll(int userid){
    34. List list=null;
    35. try {
    36. list = oDao.selectAll(userid);
    37. for(Order o :list) {
    38. List l = oDao.selectAllItem(o.getId());
    39. o.setItemList(l);
    40. }
    41. } catch (SQLException e) {
    42. // TODO Auto-generated catch block
    43. e.printStackTrace();
    44. }
    45. return list;
    46. }
    47. public Page getOrderPage(int status,int pageNumber) {
    48. Page p = new Page();
    49. p.setPageNumber(pageNumber);
    50. int pageSize = 10;
    51. int totalCount = 0;
    52. try {
    53. totalCount = oDao.getOrderCount(status);
    54. } catch (SQLException e) {
    55. // TODO Auto-generated catch block
    56. e.printStackTrace();
    57. }
    58. p.SetPageSizeAndTotalCount(pageSize, totalCount);
    59. List list=null;
    60. try {
    61. list = oDao.selectOrderList(status, pageNumber, pageSize);
    62. for(Order o :(List)list) {
    63. List l = oDao.selectAllItem(o.getId());
    64. o.setItemList(l);
    65. }
    66. } catch (SQLException e) {
    67. // TODO Auto-generated catch block
    68. e.printStackTrace();
    69. }
    70. p.setList(list);
    71. return p;
    72. }
    73. public void updateStatus(int id,int status) {
    74. try {
    75. oDao.updateStatus(id, status);
    76. } catch (SQLException e) {
    77. // TODO Auto-generated catch block
    78. e.printStackTrace();
    79. }
    80. }
    81. public void delete(int id) {
    82. Connection con = null;
    83. try {
    84. con = DBUtil.getDataSource().getConnection();
    85. con.setAutoCommit(false);
    86. oDao.deleteOrderItem(con, id);
    87. oDao.deleteOrder(con, id);
    88. con.commit();
    89. } catch (SQLException e) {
    90. // TODO Auto-generated catch block
    91. e.printStackTrace();
    92. if(con!=null)
    93. try {
    94. con.rollback();
    95. } catch (SQLException e1) {
    96. // TODO Auto-generated catch block
    97. e1.printStackTrace();
    98. }
    99. }
    100. }
    101. }

    TypeService

    1. package service;
    2. import dao.TypeDao;
    3. import model.Type;
    4. import java.sql.SQLException;
    5. import java.util.List;
    6. public class TypeService {
    7. TypeDao tDao=new TypeDao();
    8. public List GetAllType()
    9. {
    10. List list=null;
    11. try {
    12. list=tDao.GetAllType();
    13. } catch (SQLException e) {
    14. e.printStackTrace();
    15. }
    16. return list;
    17. }
    18. public Type selectTypeNameByID(int typeid)
    19. {
    20. Type type=null;
    21. try {
    22. type=tDao.selectTypeNameByID(typeid);
    23. } catch (SQLException e) {
    24. e.printStackTrace();
    25. }
    26. return type;
    27. }
    28. public Type select(int id) {
    29. Type t=null;
    30. try {
    31. t = tDao.select(id);
    32. } catch (SQLException e) {
    33. // TODO Auto-generated catch block
    34. e.printStackTrace();
    35. }
    36. return t;
    37. }
    38. public void insert(Type t) {
    39. try {
    40. tDao.insert(t);
    41. } catch (SQLException e) {
    42. // TODO Auto-generated catch block
    43. e.printStackTrace();
    44. }
    45. }
    46. public void update(Type t) {
    47. try {
    48. tDao.update(t);
    49. } catch (SQLException e) {
    50. // TODO Auto-generated catch block
    51. e.printStackTrace();
    52. }
    53. }
    54. public boolean delete(int id) {
    55. try {
    56. tDao.delete(id);
    57. return true;
    58. } catch (SQLException e) {
    59. // TODO Auto-generated catch block
    60. e.printStackTrace();
    61. return false;
    62. }
    63. }
    64. }

    UserService

    1. package service;
    2. import dao.UserDao;
    3. import model.Page;
    4. import model.User;
    5. import java.sql.SQLException;
    6. import java.util.List;
    7. public class UserService {
    8. private UserDao uDao = new UserDao();
    9. public boolean register(User user) {
    10. try {
    11. if(uDao.isUsernameExist(user.getUsername())) {
    12. return false;
    13. }
    14. if(uDao.isEmailExist(user.getEmail())) {
    15. return false;
    16. }
    17. uDao.addUser(user);
    18. return true;
    19. } catch (SQLException e) {
    20. // TODO Auto-generated catch block
    21. e.printStackTrace();
    22. }
    23. return false;
    24. }
    25. public User login(String ue,String password) {
    26. User user=null;
    27. try {
    28. user = uDao.selectByUsernamePassword(ue, password);
    29. } catch (SQLException e) {
    30. // TODO Auto-generated catch block
    31. e.printStackTrace();
    32. }
    33. if(user!=null) {
    34. return user;
    35. }
    36. try {
    37. user=uDao.selectByEmailPassword(ue, password);
    38. } catch (SQLException e) {
    39. // TODO Auto-generated catch block
    40. e.printStackTrace();
    41. }
    42. if(user!=null) {
    43. return user;
    44. }
    45. return null;
    46. }
    47. public User selectById(int id) {
    48. User u=null;
    49. try {
    50. u = uDao.selectById(id);
    51. } catch (SQLException e) {
    52. // TODO Auto-generated catch block
    53. e.printStackTrace();
    54. }
    55. return u;
    56. }
    57. public void updateUserAddress(User user) {
    58. try {
    59. uDao.updateUserAddress(user);
    60. } catch (SQLException e) {
    61. // TODO Auto-generated catch block
    62. e.printStackTrace();
    63. }
    64. }
    65. public void updatePwd(User user) {
    66. try {
    67. uDao.updatePwd(user);
    68. } catch (SQLException e) {
    69. // TODO Auto-generated catch block
    70. e.printStackTrace();
    71. }
    72. }
    73. public Page getUserPage(int pageNumber) {
    74. Page p = new Page();
    75. p.setPageNumber(pageNumber);
    76. int pageSize = 7;
    77. int totalCount = 0;
    78. try {
    79. totalCount = uDao.selectUserCount();
    80. } catch (SQLException e) {
    81. // TODO Auto-generated catch block
    82. e.printStackTrace();
    83. }
    84. p.SetPageSizeAndTotalCount(pageSize, totalCount);
    85. List list=null;
    86. try {
    87. list = uDao.selectUserList( pageNumber, pageSize);
    88. } catch (SQLException e) {
    89. // TODO Auto-generated catch block
    90. e.printStackTrace();
    91. }
    92. p.setList(list);
    93. return p;
    94. }
    95. public boolean delete(int id ) {
    96. try {
    97. uDao.delete(id);
    98. return true;
    99. } catch (SQLException e) {
    100. // TODO Auto-generated catch block
    101. e.printStackTrace();
    102. return false;
    103. }
    104. }
    105. }

    如果也想学习本系统,下面领取。关注并回复:070jsp

     

  • 相关阅读:
    【机器学习6】概率图模型
    vue2_路由01_路由的基本使用
    Linux常见面试题
    Oauth2.0的内容
    Modbus协议
    内中断(一)
    MySQL索引
    lua-arm平台交叉编译
    分布式事务-常见解决方案
    【算法leetcode】2325. 解密消息(rust和go重拳出击)
  • 原文地址:https://blog.csdn.net/m0_74967853/article/details/128031749