作者主页:夜未央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
- package com.web.shopservlet;
-
-
- import java.io.IOException;
- import java.io.PrintWriter;
-
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
-
- import com.hr.dao.ESDao;
- import com.hr.entity.EASYBUY_ORDER_DETAIL;
- import com.hr.entity.EASYBUY_USER;
- import com.hr.util.EncodeUtil;
-
-
- public class gmServlet extends HttpServlet {
- @Override
- protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
- throws ServletException, IOException {
- arg1.setContentType("text/html;charset=utf-8");
- PrintWriter out=arg1.getWriter();
- EncodeUtil.encode(arg0);
- HttpSession session=arg0.getSession();
- EASYBUY_USER list=(EASYBUY_USER)session.getAttribute("name");
- //用户id
- String id=list.getEU_USER_ID();
- //用户姓名
- String name=list.getEU_USER_NAME();
- //用户地址
- String address=list.getEU_ADDRESS();
- //总价钱
- String price=arg0.getParameter("jstext");
-
- //商品id
- String [] EP_ID=arg0.getParameterValues("spID");
- //购买数量
- String [] quantity=arg0.getParameterValues("number");
- //商品单价
- String [] sPPrice=arg0.getParameterValues("sPPrice");
-
- //购买后对商品表的库存进行修改
- for(int i=0;i
- int count5=ESDao.updateStock(Integer.parseInt(quantity[i]),Integer.parseInt(EP_ID[i]));
- }
- //商品单个总价
- int [] pprice=new int[EP_ID.length];
- for(int i=0;i
- pprice[i]=Integer.parseInt(quantity[i])*Integer.parseInt(sPPrice[i]);
- }
- /得到序列
- //往订单表里添加数据
- int count=ESDao.insertDD(id, name, address,Integer.parseInt(price));
- int getSequenceId=ESDao.getSequenceId();
- //循环往订单详情添加
- for(int i=0;i
- EASYBUY_ORDER_DETAIL eod=new EASYBUY_ORDER_DETAIL(1,getSequenceId,Integer.parseInt(EP_ID[i]),Integer.parseInt(quantity[i]),pprice[i]);
- int count2=ESDao.eodInsert(eod);
- }
-
-
-
- // 开单后,修改购物车
- String [] esID=arg0.getParameterValues("esID");
- for(int i=0;i
- int count3 =ESDao.esdelete(Integer.parseInt(esID[i]));
- }
- /
- if(count>0){
-
- out.print("");
- out.close();
- }else{
- out.print("");
- out.close();
- }
- }
- }
ShopSelect
- package com.web.shopservlet;
-
-
- //订单表数据的查询
-
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
-
-
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import com.hr.dao.ESDao;
- import com.hr.entity.EASYBUY_USER;
- import com.hr.entity.eb_shop;
- import com.hr.util.EncodeUtil;
-
- public class ShopSelect extends HttpServlet {
- @Override
- protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
- throws ServletException, IOException {
- EncodeUtil.encode(arg0);
- arg1.setContentType("text/html;charset=utf-8");
- PrintWriter out = arg1.getWriter();
- HttpSession session=arg0.getSession();
- EASYBUY_USER userCZ=(EASYBUY_USER)session.getAttribute("name");
- if(userCZ!=null){
- // System.out.println("登录好了");
- EASYBUY_USER eu=(EASYBUY_USER)session.getAttribute("name");
- String id=(String)eu.getEU_USER_ID();
- ArrayList
list=ESDao.getShop(id); - arg0.setAttribute("shoplist",list);
- arg0.getRequestDispatcher("shopping.jsp").forward(arg0, arg1);
- }else{
- out.print("");
- out.close();
-
- }
- }
- }
ESDao
- package com.hr.dao;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
-
- import com.hr.entity.EASYBUY_ORDER_DETAIL;
- import com.hr.entity.EASYBUY_PRODUCT_CATEGORY;
- import com.hr.entity.EASYBUY_USER;
- import com.hr.entity.eb_shop;
-
- public class ESDao {
- /**
- * 两张表联查做购物车
- */
- public static ArrayList
getShop(String id){ - ArrayList
list=new ArrayList(); - Connection conn=Basedao.getconn();
- PreparedStatement ps=null;
- ResultSet rs=null;
- try {
- ps=conn.prepareStatement("select * from EASYBUY_SHOP where es_EU_USER_ID=? and ES_VALID=1 order by es_id desc");
- ps.setString(1,id);
- rs=ps.executeQuery();
- while(rs.next()){
- eb_shop es=new eb_shop(
- rs.getInt("es_id"),
- rs.getString("es_ep_file_name"),
- rs.getString("es_ep_name"),
- rs.getInt("es_ep_price"),
- rs.getInt("es_eod_quantity"),
- rs.getInt("es_ep_stock"),
- rs.getInt("es_ep_id"),
- rs.getString("es_EU_USER_ID"),
- rs.getInt("es_valid")
- );
- list.add(es);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- Basedao.closeall(rs, ps, conn);
-
- }
- return list;
- }
- /*
- *
- *修改订单数量 加
- */
- public static int updateJia(int id){
- String sql="update EASYBUY_SHOP set es_eod_quantity=es_eod_quantity+1 where es_id=?";
- Object [] params={id};
- return Basedao.exectuIUD(sql, params);
- }
-
- /*
- *
- *修改订单数量 减
- */
- public static int updateJian(int id){
- String sql="update EASYBUY_SHOP set es_eod_quantity=es_eod_quantity-1 where es_id=?";
- Object [] params={id};
- return Basedao.exectuIUD(sql, params);
- }
- /*
- *
- * 修改订单数量,自己输入
- */
- public static int updateClose(eb_shop es){
- String sql="update EASYBUY_SHOP set es_eod_quantity=? where es_id=?";
- Object [] params={es.es_eod_quantity,es.es_id};
- return Basedao.exectuIUD(sql, params);
- }
- /**
- * 修改订单为2
- * @param id
- * @return
- */
- public static int getDelete(int id){
- String sql="update EASYBUY_SHOP set es_vaild=2 where es_id=?";
- Object[] params={id};
- return Basedao.exectuIUD(sql, params);
- }
- /*
- *
- * 订单表的添加
- *
- */
- public static int insertDD(String id,String name,String address,int price){
- String sql="insert into EASYBUY_ORDER values(null,?,?,?,now(),?,1,1)";
- Object [] params={id,name,address,price};
- return Basedao.exectuIUD(sql, params);
- }
- /*
- * 得到序列
- */
- public static int getSequenceId(){
- int id = 0;
- Connection conn = Basedao.getconn();
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- ps = conn.prepareStatement("select EO_ID from easybuy_order order by EO_ID desc limit 0,1");
- rs = ps.executeQuery();
- if(rs.next()){
- id = rs.getInt(1);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- Basedao.closeall(rs, ps, conn);
- }
- return id;
- }
- /*
- *
- * 订单详细表的添加
- */
- public static int eodInsert(EASYBUY_ORDER_DETAIL eod){
- String sql="insert into EASYBUY_ORDER_DETAIL values(null,?,?,?,?)";
- Object [] params={eod.getEO_ID(),eod.getEP_ID(),eod.getEOD_QUANTITY(),eod.getEOD_COST()};
- return Basedao.exectuIUD(sql, params);
- }
- /*
- *
- * 购物单的修改
- */
- public static int esdelete(int id){
- String sql="update EASYBUY_SHOP set es_valid=2 where es_id=?";
- Object [] params={id};
- return Basedao.exectuIUD(sql, params);
- }
- //kucun
- public static int updateStock(int stock,int id){
- String sql="update EASYBUY_PRODUCT set ep_stock=ep_stock-? where ep_id=?";
- Object [] params={stock,id};
- return Basedao.exectuIUD(sql, params);
- }
-
- public static int insert(eb_shop sp){
- String sql = "insert into easybuy_shop values(null,?,?,?,?,?,?,?,1)";
- Object[] params = {sp.getEs_ep_file_name(),
- sp.getEs_ep_name(),
- sp.getEs_ep_price(),
- sp.getEs_eod_quantity(),
- sp.getEs_ep_stock(),
- sp.getEs_ep_id(),
- sp.getEs_EU_USER_ID()};
- return Basedao.exectuIUD(sql, params);
- }
-
- public static int getDeleteDD(int id){
- String sql="delete from easybuy_shop where es_id=?";
- Object [] params={id};
- return Basedao.exectuIUD(sql, params);
- }
- }
EASYBUY_USERDao
- package com.hr.dao;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
-
- import com.hr.entity.EASYBUY_USER;
-
- public class EASYBUY_USERDao {
- /**
- * 分页查询
- */
- public static ArrayList
selectAll(int cpage,int count){ - ArrayList
list = new ArrayList(); - ResultSet rs = null;
- Connection conn = Basedao.getconn();
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement("select * from EASYBUY_USER order by EU_BIRTHDAY desc"+
- " limit ?, ?");
- ps.setInt(1, count*(cpage-1));
- ps.setInt(2, count);
- rs = ps.executeQuery();
- while(rs.next()){
- EASYBUY_USER u = new EASYBUY_USER(rs.getString("EU_USER_ID"),
- rs.getString("EU_USER_NAME"),
- rs.getString("EU_PASSWORD"),
- rs.getString("EU_SEX"),
- rs.getString("EU_BIRTHDAY"),
- rs.getString("EU_IDENTITY_CODE"),
- rs.getString("EU_EMAIL"),
- rs.getString("EU_MOBILE"),
- rs.getString("EU_ADDRESS"),
- rs.getInt("EU_STATUS"));
- list.add(u);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally {
- Basedao.closeall(rs, ps, conn);
- }
- return list;
- }
- /**
- * 查询所有
- * @return
- */
- public static ArrayList
selectAll(){ - ArrayList
list = new ArrayList(); - ResultSet rs = null;
- Connection conn = Basedao.getconn();
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement("select * from EASYBUY_USER");
- rs = ps.executeQuery();
- while(rs.next()){
- EASYBUY_USER u = new EASYBUY_USER(rs.getString("EU_USER_ID"),
- rs.getString("EU_USER_NAME"),
- rs.getString("EU_PASSWORD"),
- rs.getString("EU_SEX"),
- rs.getString("EU_BIRTHDAY"),
- rs.getString("EU_IDENTITY_CODE"),
- rs.getString("EU_EMAIL"),
- rs.getString("EU_MOBILE"),
- rs.getString("EU_ADDRESS"),
- rs.getInt("EU_STATUS"));
- list.add(u);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally {
- Basedao.closeall(rs, ps, conn);
- }
- return list;
- }
-
- /**
- * 根据id查询单个
- * @param id
- * @return
- */
- public static EASYBUY_USER selectById(String id){
- EASYBUY_USER u = null;
- ResultSet rs = null;
- Connection conn = Basedao.getconn();
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement("select m.*,DATE_FORMAT(m.eu_birthday,'%Y-%m-%d')birthday from EASYBUY_USER m where EU_USER_ID=?");
- ps.setString(1, id);
- rs = ps.executeQuery();
- while(rs.next()){
- u = new EASYBUY_USER(rs.getString("EU_USER_ID"),
- rs.getString("EU_USER_NAME"),
- rs.getString("EU_PASSWORD"),
- rs.getString("EU_SEX"),
- rs.getString("birthday"),
- rs.getString("EU_IDENTITY_CODE"),
- rs.getString("EU_EMAIL"),
- rs.getString("EU_MOBILE"),
- rs.getString("EU_ADDRESS"),
- rs.getInt("EU_STATUS"));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally {
- Basedao.closeall(rs, ps, conn);
- }
- return u;
- }
- /**
- * 查看是否有此人
- * @param id
- * @return
- */
- public static int selectByName(String id){
- int count=0;
- ResultSet rs = null;
- Connection conn = Basedao.getconn();
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement("select count(*) from EASYBUY_USER where EU_USER_ID=?");
- ps.setString(1, id);
- rs = ps.executeQuery();
- while(rs.next()){
- count=rs.getInt(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- Basedao.closeall(rs, ps, conn);
- }
- return count;
- }
- /**
- * 看用户名和密码对不对
- */
- public static int selectByNM(String name,String pwd){
- int count=0;
- ResultSet rs = null;
- Connection conn = Basedao.getconn();
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement("select count(*) from EASYBUY_USER where EU_USER_ID=? and EU_PASSWORD=?");
- ps.setString(1, name);
- ps.setString(2, pwd);
- rs = ps.executeQuery();
- while(rs.next()){
- count=rs.getInt(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- Basedao.closeall(rs, ps, conn);
- }
- return count;
- }
- /**
- * 判断是普通用户还是管理员
- * @param name
- * @param pwd
- * @return
- */
- public static EASYBUY_USER selectAdmin(String name,String pwd){
- EASYBUY_USER user=null;
- ResultSet rs = null;
- Connection conn = Basedao.getconn();
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement("select * from EASYBUY_USER where EU_USER_ID=? and EU_PASSWORD=?");
- ps.setString(1, name);
- ps.setString(2, pwd);
- rs = ps.executeQuery();
- while(rs.next()){
- user = new EASYBUY_USER(rs.getString("EU_USER_ID"),
- rs.getString("EU_USER_NAME"),
- rs.getString("EU_PASSWORD"),
- rs.getString("EU_SEX"),
- rs.getString("EU_BIRTHDAY"),
- rs.getString("EU_IDENTITY_CODE"),
- rs.getString("EU_EMAIL"),
- rs.getString("EU_MOBILE"),
- rs.getString("EU_ADDRESS"),
- rs.getInt("EU_STATUS"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }finally {
- Basedao.closeall(rs, ps, conn);
- }
- return user;
- }
- /**
- * 分页管理
- * @param u
- * @return
- */
- public static int totalPage(int count){
- int tpage=1;
- Connection conn=Basedao.getconn();
- PreparedStatement ps=null;
- ResultSet rs=null;
- try {
- ps=conn.prepareStatement("select count(*) from EASYBUY_USER");
- rs=ps.executeQuery();
- while(rs.next()){
- int sum=rs.getInt(1);
- if(sum%count==0){
- tpage=sum/count;
- }else{
- tpage=sum/count+1;
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }finally{
- Basedao.closeall(rs, ps, conn);
- }
- return tpage;
- }
- public static int insert(EASYBUY_USER u){
- String sql = "insert into EASYBUY_USER values(?,?,?,?,DATE_FORMAT(?,'%Y-%m-%d'),?,?,?,?,?)";
- Object[] params = {u.getEU_USER_ID(),
- u.getEU_USER_NAME(),
- u.getEU_PASSWORD(),
- u.getEU_SEX(),
- u.getEU_BIRTHDAY(),
- u.getEU_IDENTITY_CODE(),
- u.getEU_EMAIL(),
- u.getEU_MOBILE(),
- u.getEU_ADDRESS(),
- u.getEU_STATUS()};
- return Basedao.exectuIUD(sql, params);
- }
-
- public static int update(EASYBUY_USER u){
- String sql = "update EASYBUY_USER set EU_USER_NAME=?," +
- "EU_PASSWORD=?," +
- "EU_SEX=?," +
- "EU_BIRTHDAY=DATE_FORMAT(?,'%Y-%m-%d')," +
- "EU_IDENTITY_CODE=?," +
- "EU_EMAIL=?," +
- "EU_MOBILE=?," +
- "EU_ADDRESS=?," +
- "EU_STATUS=? " +
- "where EU_USER_ID=?";
- Object[] params = {u.getEU_USER_NAME(),
- u.getEU_PASSWORD(),
- u.getEU_SEX(),
- u.getEU_BIRTHDAY(),
- u.getEU_IDENTITY_CODE(),
- u.getEU_EMAIL(),
- u.getEU_MOBILE(),
- u.getEU_ADDRESS(),
- u.getEU_STATUS(),
- u.getEU_USER_ID()};
- return Basedao.exectuIUD(sql, params);
- }
-
- public static int del(String id){
- String sql = "delete from EASYBUY_USER where EU_USER_ID=? and EU_USER_ID!='admin'";
- Object[] params = {id};
- return Basedao.exectuIUD(sql, params);
- }
- }
如果也想学习本系统,下面领取。关注并回复: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