• 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+JavaScript+java+servlet+mysql

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中src/com/hr/dao/Basedao.java配置文件中的数据库配置改为自己的配置;
    4. 运行项目,输入http://localhost:8080/ 登录
    管理员账号/密码:admin/admin 

    用户账号/密码:user/123456

    运行截图

    前台界面-用户角色

     

     

     

     

     

     

    后台界面

     

     

     

     

     

    相关代码 

    gmServlet

    1. package com.web.shopservlet;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import javax.servlet.ServletException;
    5. import javax.servlet.http.HttpServlet;
    6. import javax.servlet.http.HttpServletRequest;
    7. import javax.servlet.http.HttpServletResponse;
    8. import javax.servlet.http.HttpSession;
    9. import com.hr.dao.ESDao;
    10. import com.hr.entity.EASYBUY_ORDER_DETAIL;
    11. import com.hr.entity.EASYBUY_USER;
    12. import com.hr.util.EncodeUtil;
    13. public class gmServlet extends HttpServlet {
    14. @Override
    15. protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
    16. throws ServletException, IOException {
    17. arg1.setContentType("text/html;charset=utf-8");
    18. PrintWriter out=arg1.getWriter();
    19. EncodeUtil.encode(arg0);
    20. HttpSession session=arg0.getSession();
    21. EASYBUY_USER list=(EASYBUY_USER)session.getAttribute("name");
    22. //用户id
    23. String id=list.getEU_USER_ID();
    24. //用户姓名
    25. String name=list.getEU_USER_NAME();
    26. //用户地址
    27. String address=list.getEU_ADDRESS();
    28. //总价钱
    29. String price=arg0.getParameter("jstext");
    30. //商品id
    31. String [] EP_ID=arg0.getParameterValues("spID");
    32. //购买数量
    33. String [] quantity=arg0.getParameterValues("number");
    34. //商品单价
    35. String [] sPPrice=arg0.getParameterValues("sPPrice");
    36. //购买后对商品表的库存进行修改
    37. for(int i=0;i
    38. int count5=ESDao.updateStock(Integer.parseInt(quantity[i]),Integer.parseInt(EP_ID[i]));
    39. }
    40. //商品单个总价
    41. int [] pprice=new int[EP_ID.length];
    42. for(int i=0;i
    43. pprice[i]=Integer.parseInt(quantity[i])*Integer.parseInt(sPPrice[i]);
    44. }
    45. /得到序列
    46. //往订单表里添加数据
    47. int count=ESDao.insertDD(id, name, address,Integer.parseInt(price));
    48. int getSequenceId=ESDao.getSequenceId();
    49. //循环往订单详情添加
    50. for(int i=0;i
    51. EASYBUY_ORDER_DETAIL eod=new EASYBUY_ORDER_DETAIL(1,getSequenceId,Integer.parseInt(EP_ID[i]),Integer.parseInt(quantity[i]),pprice[i]);
    52. int count2=ESDao.eodInsert(eod);
    53. }
    54. // 开单后,修改购物车
    55. String [] esID=arg0.getParameterValues("esID");
    56. for(int i=0;i
    57. int count3 =ESDao.esdelete(Integer.parseInt(esID[i]));
    58. }
    59. /
    60. if(count>0){
    61. out.print("");
    62. out.close();
    63. }else{
    64. out.print("");
    65. out.close();
    66. }
    67. }
    68. }

    ShopSelect

    1. package com.web.shopservlet;
    2. //订单表数据的查询
    3. import java.io.IOException;
    4. import java.io.PrintWriter;
    5. import java.util.ArrayList;
    6. import javax.servlet.ServletException;
    7. import javax.servlet.http.HttpServlet;
    8. import javax.servlet.http.HttpServletRequest;
    9. import javax.servlet.http.HttpServletResponse;
    10. import javax.servlet.http.HttpSession;
    11. import com.hr.dao.ESDao;
    12. import com.hr.entity.EASYBUY_USER;
    13. import com.hr.entity.eb_shop;
    14. import com.hr.util.EncodeUtil;
    15. public class ShopSelect extends HttpServlet {
    16. @Override
    17. protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
    18. throws ServletException, IOException {
    19. EncodeUtil.encode(arg0);
    20. arg1.setContentType("text/html;charset=utf-8");
    21. PrintWriter out = arg1.getWriter();
    22. HttpSession session=arg0.getSession();
    23. EASYBUY_USER userCZ=(EASYBUY_USER)session.getAttribute("name");
    24. if(userCZ!=null){
    25. // System.out.println("登录好了");
    26. EASYBUY_USER eu=(EASYBUY_USER)session.getAttribute("name");
    27. String id=(String)eu.getEU_USER_ID();
    28. ArrayList list=ESDao.getShop(id);
    29. arg0.setAttribute("shoplist",list);
    30. arg0.getRequestDispatcher("shopping.jsp").forward(arg0, arg1);
    31. }else{
    32. out.print("");
    33. out.close();
    34. }
    35. }
    36. }

    ESDao

    1. package com.hr.dao;
    2. import java.sql.Connection;
    3. import java.sql.PreparedStatement;
    4. import java.sql.ResultSet;
    5. import java.sql.SQLException;
    6. import java.util.ArrayList;
    7. import com.hr.entity.EASYBUY_ORDER_DETAIL;
    8. import com.hr.entity.EASYBUY_PRODUCT_CATEGORY;
    9. import com.hr.entity.EASYBUY_USER;
    10. import com.hr.entity.eb_shop;
    11. public class ESDao {
    12. /**
    13. * 两张表联查做购物车
    14. */
    15. public static ArrayList getShop(String id){
    16. ArrayList list=new ArrayList();
    17. Connection conn=Basedao.getconn();
    18. PreparedStatement ps=null;
    19. ResultSet rs=null;
    20. try {
    21. ps=conn.prepareStatement("select * from EASYBUY_SHOP where es_EU_USER_ID=? and ES_VALID=1 order by es_id desc");
    22. ps.setString(1,id);
    23. rs=ps.executeQuery();
    24. while(rs.next()){
    25. eb_shop es=new eb_shop(
    26. rs.getInt("es_id"),
    27. rs.getString("es_ep_file_name"),
    28. rs.getString("es_ep_name"),
    29. rs.getInt("es_ep_price"),
    30. rs.getInt("es_eod_quantity"),
    31. rs.getInt("es_ep_stock"),
    32. rs.getInt("es_ep_id"),
    33. rs.getString("es_EU_USER_ID"),
    34. rs.getInt("es_valid")
    35. );
    36. list.add(es);
    37. }
    38. } catch (SQLException e) {
    39. // TODO Auto-generated catch block
    40. e.printStackTrace();
    41. }finally{
    42. Basedao.closeall(rs, ps, conn);
    43. }
    44. return list;
    45. }
    46. /*
    47. *
    48. *修改订单数量 加
    49. */
    50. public static int updateJia(int id){
    51. String sql="update EASYBUY_SHOP set es_eod_quantity=es_eod_quantity+1 where es_id=?";
    52. Object [] params={id};
    53. return Basedao.exectuIUD(sql, params);
    54. }
    55. /*
    56. *
    57. *修改订单数量 减
    58. */
    59. public static int updateJian(int id){
    60. String sql="update EASYBUY_SHOP set es_eod_quantity=es_eod_quantity-1 where es_id=?";
    61. Object [] params={id};
    62. return Basedao.exectuIUD(sql, params);
    63. }
    64. /*
    65. *
    66. * 修改订单数量,自己输入
    67. */
    68. public static int updateClose(eb_shop es){
    69. String sql="update EASYBUY_SHOP set es_eod_quantity=? where es_id=?";
    70. Object [] params={es.es_eod_quantity,es.es_id};
    71. return Basedao.exectuIUD(sql, params);
    72. }
    73. /**
    74. * 修改订单为2
    75. * @param id
    76. * @return
    77. */
    78. public static int getDelete(int id){
    79. String sql="update EASYBUY_SHOP set es_vaild=2 where es_id=?";
    80. Object[] params={id};
    81. return Basedao.exectuIUD(sql, params);
    82. }
    83. /*
    84. *
    85. * 订单表的添加
    86. *
    87. */
    88. public static int insertDD(String id,String name,String address,int price){
    89. String sql="insert into EASYBUY_ORDER values(null,?,?,?,now(),?,1,1)";
    90. Object [] params={id,name,address,price};
    91. return Basedao.exectuIUD(sql, params);
    92. }
    93. /*
    94. * 得到序列
    95. */
    96. public static int getSequenceId(){
    97. int id = 0;
    98. Connection conn = Basedao.getconn();
    99. PreparedStatement ps = null;
    100. ResultSet rs = null;
    101. try {
    102. ps = conn.prepareStatement("select EO_ID from easybuy_order order by EO_ID desc limit 0,1");
    103. rs = ps.executeQuery();
    104. if(rs.next()){
    105. id = rs.getInt(1);
    106. }
    107. } catch (SQLException e) {
    108. // TODO Auto-generated catch block
    109. e.printStackTrace();
    110. } finally {
    111. Basedao.closeall(rs, ps, conn);
    112. }
    113. return id;
    114. }
    115. /*
    116. *
    117. * 订单详细表的添加
    118. */
    119. public static int eodInsert(EASYBUY_ORDER_DETAIL eod){
    120. String sql="insert into EASYBUY_ORDER_DETAIL values(null,?,?,?,?)";
    121. Object [] params={eod.getEO_ID(),eod.getEP_ID(),eod.getEOD_QUANTITY(),eod.getEOD_COST()};
    122. return Basedao.exectuIUD(sql, params);
    123. }
    124. /*
    125. *
    126. * 购物单的修改
    127. */
    128. public static int esdelete(int id){
    129. String sql="update EASYBUY_SHOP set es_valid=2 where es_id=?";
    130. Object [] params={id};
    131. return Basedao.exectuIUD(sql, params);
    132. }
    133. //kucun
    134. public static int updateStock(int stock,int id){
    135. String sql="update EASYBUY_PRODUCT set ep_stock=ep_stock-? where ep_id=?";
    136. Object [] params={stock,id};
    137. return Basedao.exectuIUD(sql, params);
    138. }
    139. public static int insert(eb_shop sp){
    140. String sql = "insert into easybuy_shop values(null,?,?,?,?,?,?,?,1)";
    141. Object[] params = {sp.getEs_ep_file_name(),
    142. sp.getEs_ep_name(),
    143. sp.getEs_ep_price(),
    144. sp.getEs_eod_quantity(),
    145. sp.getEs_ep_stock(),
    146. sp.getEs_ep_id(),
    147. sp.getEs_EU_USER_ID()};
    148. return Basedao.exectuIUD(sql, params);
    149. }
    150. public static int getDeleteDD(int id){
    151. String sql="delete from easybuy_shop where es_id=?";
    152. Object [] params={id};
    153. return Basedao.exectuIUD(sql, params);
    154. }
    155. }

    EASYBUY_USERDao

    1. package com.hr.dao;
    2. import java.sql.Connection;
    3. import java.sql.PreparedStatement;
    4. import java.sql.ResultSet;
    5. import java.sql.SQLException;
    6. import java.util.ArrayList;
    7. import com.hr.entity.EASYBUY_USER;
    8. public class EASYBUY_USERDao {
    9. /**
    10. * 分页查询
    11. */
    12. public static ArrayList selectAll(int cpage,int count){
    13. ArrayList list = new ArrayList();
    14. ResultSet rs = null;
    15. Connection conn = Basedao.getconn();
    16. PreparedStatement ps = null;
    17. try {
    18. ps = conn.prepareStatement("select * from EASYBUY_USER order by EU_BIRTHDAY desc"+
    19. " limit ?, ?");
    20. ps.setInt(1, count*(cpage-1));
    21. ps.setInt(2, count);
    22. rs = ps.executeQuery();
    23. while(rs.next()){
    24. EASYBUY_USER u = new EASYBUY_USER(rs.getString("EU_USER_ID"),
    25. rs.getString("EU_USER_NAME"),
    26. rs.getString("EU_PASSWORD"),
    27. rs.getString("EU_SEX"),
    28. rs.getString("EU_BIRTHDAY"),
    29. rs.getString("EU_IDENTITY_CODE"),
    30. rs.getString("EU_EMAIL"),
    31. rs.getString("EU_MOBILE"),
    32. rs.getString("EU_ADDRESS"),
    33. rs.getInt("EU_STATUS"));
    34. list.add(u);
    35. }
    36. } catch (SQLException e) {
    37. // TODO Auto-generated catch block
    38. e.printStackTrace();
    39. }finally {
    40. Basedao.closeall(rs, ps, conn);
    41. }
    42. return list;
    43. }
    44. /**
    45. * 查询所有
    46. * @return
    47. */
    48. public static ArrayList selectAll(){
    49. ArrayList list = new ArrayList();
    50. ResultSet rs = null;
    51. Connection conn = Basedao.getconn();
    52. PreparedStatement ps = null;
    53. try {
    54. ps = conn.prepareStatement("select * from EASYBUY_USER");
    55. rs = ps.executeQuery();
    56. while(rs.next()){
    57. EASYBUY_USER u = new EASYBUY_USER(rs.getString("EU_USER_ID"),
    58. rs.getString("EU_USER_NAME"),
    59. rs.getString("EU_PASSWORD"),
    60. rs.getString("EU_SEX"),
    61. rs.getString("EU_BIRTHDAY"),
    62. rs.getString("EU_IDENTITY_CODE"),
    63. rs.getString("EU_EMAIL"),
    64. rs.getString("EU_MOBILE"),
    65. rs.getString("EU_ADDRESS"),
    66. rs.getInt("EU_STATUS"));
    67. list.add(u);
    68. }
    69. } catch (SQLException e) {
    70. // TODO Auto-generated catch block
    71. e.printStackTrace();
    72. }finally {
    73. Basedao.closeall(rs, ps, conn);
    74. }
    75. return list;
    76. }
    77. /**
    78. * 根据id查询单个
    79. * @param id
    80. * @return
    81. */
    82. public static EASYBUY_USER selectById(String id){
    83. EASYBUY_USER u = null;
    84. ResultSet rs = null;
    85. Connection conn = Basedao.getconn();
    86. PreparedStatement ps = null;
    87. try {
    88. ps = conn.prepareStatement("select m.*,DATE_FORMAT(m.eu_birthday,'%Y-%m-%d')birthday from EASYBUY_USER m where EU_USER_ID=?");
    89. ps.setString(1, id);
    90. rs = ps.executeQuery();
    91. while(rs.next()){
    92. u = new EASYBUY_USER(rs.getString("EU_USER_ID"),
    93. rs.getString("EU_USER_NAME"),
    94. rs.getString("EU_PASSWORD"),
    95. rs.getString("EU_SEX"),
    96. rs.getString("birthday"),
    97. rs.getString("EU_IDENTITY_CODE"),
    98. rs.getString("EU_EMAIL"),
    99. rs.getString("EU_MOBILE"),
    100. rs.getString("EU_ADDRESS"),
    101. rs.getInt("EU_STATUS"));
    102. }
    103. } catch (SQLException e) {
    104. // TODO Auto-generated catch block
    105. e.printStackTrace();
    106. }finally {
    107. Basedao.closeall(rs, ps, conn);
    108. }
    109. return u;
    110. }
    111. /**
    112. * 查看是否有此人
    113. * @param id
    114. * @return
    115. */
    116. public static int selectByName(String id){
    117. int count=0;
    118. ResultSet rs = null;
    119. Connection conn = Basedao.getconn();
    120. PreparedStatement ps = null;
    121. try {
    122. ps = conn.prepareStatement("select count(*) from EASYBUY_USER where EU_USER_ID=?");
    123. ps.setString(1, id);
    124. rs = ps.executeQuery();
    125. while(rs.next()){
    126. count=rs.getInt(1);
    127. }
    128. } catch (SQLException e) {
    129. e.printStackTrace();
    130. }finally {
    131. Basedao.closeall(rs, ps, conn);
    132. }
    133. return count;
    134. }
    135. /**
    136. * 看用户名和密码对不对
    137. */
    138. public static int selectByNM(String name,String pwd){
    139. int count=0;
    140. ResultSet rs = null;
    141. Connection conn = Basedao.getconn();
    142. PreparedStatement ps = null;
    143. try {
    144. ps = conn.prepareStatement("select count(*) from EASYBUY_USER where EU_USER_ID=? and EU_PASSWORD=?");
    145. ps.setString(1, name);
    146. ps.setString(2, pwd);
    147. rs = ps.executeQuery();
    148. while(rs.next()){
    149. count=rs.getInt(1);
    150. }
    151. } catch (SQLException e) {
    152. e.printStackTrace();
    153. }finally {
    154. Basedao.closeall(rs, ps, conn);
    155. }
    156. return count;
    157. }
    158. /**
    159. * 判断是普通用户还是管理员
    160. * @param name
    161. * @param pwd
    162. * @return
    163. */
    164. public static EASYBUY_USER selectAdmin(String name,String pwd){
    165. EASYBUY_USER user=null;
    166. ResultSet rs = null;
    167. Connection conn = Basedao.getconn();
    168. PreparedStatement ps = null;
    169. try {
    170. ps = conn.prepareStatement("select * from EASYBUY_USER where EU_USER_ID=? and EU_PASSWORD=?");
    171. ps.setString(1, name);
    172. ps.setString(2, pwd);
    173. rs = ps.executeQuery();
    174. while(rs.next()){
    175. user = new EASYBUY_USER(rs.getString("EU_USER_ID"),
    176. rs.getString("EU_USER_NAME"),
    177. rs.getString("EU_PASSWORD"),
    178. rs.getString("EU_SEX"),
    179. rs.getString("EU_BIRTHDAY"),
    180. rs.getString("EU_IDENTITY_CODE"),
    181. rs.getString("EU_EMAIL"),
    182. rs.getString("EU_MOBILE"),
    183. rs.getString("EU_ADDRESS"),
    184. rs.getInt("EU_STATUS"));
    185. }
    186. } catch (SQLException e) {
    187. e.printStackTrace();
    188. }finally {
    189. Basedao.closeall(rs, ps, conn);
    190. }
    191. return user;
    192. }
    193. /**
    194. * 分页管理
    195. * @param u
    196. * @return
    197. */
    198. public static int totalPage(int count){
    199. int tpage=1;
    200. Connection conn=Basedao.getconn();
    201. PreparedStatement ps=null;
    202. ResultSet rs=null;
    203. try {
    204. ps=conn.prepareStatement("select count(*) from EASYBUY_USER");
    205. rs=ps.executeQuery();
    206. while(rs.next()){
    207. int sum=rs.getInt(1);
    208. if(sum%count==0){
    209. tpage=sum/count;
    210. }else{
    211. tpage=sum/count+1;
    212. }
    213. }
    214. } catch (SQLException e) {
    215. e.printStackTrace();
    216. }finally{
    217. Basedao.closeall(rs, ps, conn);
    218. }
    219. return tpage;
    220. }
    221. public static int insert(EASYBUY_USER u){
    222. String sql = "insert into EASYBUY_USER values(?,?,?,?,DATE_FORMAT(?,'%Y-%m-%d'),?,?,?,?,?)";
    223. Object[] params = {u.getEU_USER_ID(),
    224. u.getEU_USER_NAME(),
    225. u.getEU_PASSWORD(),
    226. u.getEU_SEX(),
    227. u.getEU_BIRTHDAY(),
    228. u.getEU_IDENTITY_CODE(),
    229. u.getEU_EMAIL(),
    230. u.getEU_MOBILE(),
    231. u.getEU_ADDRESS(),
    232. u.getEU_STATUS()};
    233. return Basedao.exectuIUD(sql, params);
    234. }
    235. public static int update(EASYBUY_USER u){
    236. String sql = "update EASYBUY_USER set EU_USER_NAME=?," +
    237. "EU_PASSWORD=?," +
    238. "EU_SEX=?," +
    239. "EU_BIRTHDAY=DATE_FORMAT(?,'%Y-%m-%d')," +
    240. "EU_IDENTITY_CODE=?," +
    241. "EU_EMAIL=?," +
    242. "EU_MOBILE=?," +
    243. "EU_ADDRESS=?," +
    244. "EU_STATUS=? " +
    245. "where EU_USER_ID=?";
    246. Object[] params = {u.getEU_USER_NAME(),
    247. u.getEU_PASSWORD(),
    248. u.getEU_SEX(),
    249. u.getEU_BIRTHDAY(),
    250. u.getEU_IDENTITY_CODE(),
    251. u.getEU_EMAIL(),
    252. u.getEU_MOBILE(),
    253. u.getEU_ADDRESS(),
    254. u.getEU_STATUS(),
    255. u.getEU_USER_ID()};
    256. return Basedao.exectuIUD(sql, params);
    257. }
    258. public static int del(String id){
    259. String sql = "delete from EASYBUY_USER where EU_USER_ID=? and EU_USER_ID!='admin'";
    260. Object[] params = {id};
    261. return Basedao.exectuIUD(sql, params);
    262. }
    263. }

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

  • 相关阅读:
    【大数据入门核心技术-Hadoop】(一)Hadoop简介
    开源地图库OpenLayers的简单使用
    IDEA创建完Maven工程后,右下角一直显示正在下载Maven插件
    50个常用的Java代码示例
    连接数据库
    简单聊聊ThreadLocal吧
    GCC - 基于win10平台搭建Cmake + MinGW + gcc-arm-none 开源开发环境
    C++ Reference: Standard C++ Library reference: C Library: cwctype: wctype
    安全计算环境(设备和技术注解)
    window小技巧---------电脑自动开关机/电脑自动开机后打开应用/打开浏览器后自动响应某个页面并且f12
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126965143