基于JavaWeb实现智慧菜市场系统的设计与实现程序

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 基于JavaWeb实现智慧菜市场系统的设计与实现程序



项目编号:BS-SC-056

一,环境介绍

语言环境:Java:  jdk1.8

数据库:Mysql: mysql5.7

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

开发技术:JavaWeb开发技术(JSP,SERVLET,JDBC)

二,项目简介

本项目基于JavaWeb技术开发实现一个智慧菜市场系统。主要完成对菜市场的摊位展示和管理,商品展示和管理,相关通知通告,在线留言,在线购物等相关操作。系统用户包含前端注册用户和后台管理用户。管理用户主要实现用户管理、难位管理、商品分类管理、商品管理、公告管理、订单管理、轮播图管理、友情连接管理等。前端用户可以在线浏览菜市场摊位信息,摊位所经营的产品信息,在线添加购物车,在线购买生成订单,浏览公告信息等等。

三,系统展示

前台页面展示

商品信息查询

摊位信息展示

公告 信息展示

在线留言展示

用户注册

后台管理员管理功能

管理员管理

注册用户管理

农户管理

摊位管理

商品管理

订单管理

公告管理

系统管理

四,核心代码展示

package dao;
import com.jntoo.db.utils.StringUtil;
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import util.Info;
/**
 * 数据库连接类
 */
public class CommDAO {
    // 数据库名称
    public static final String database = "jspm12545zhcscxtdsjysx";
    // 数据库账号
    public static final String username = "root";
    // 数据库密码
    public static final String pwd = "root";
    // 是否为 mysql8.0及以上、如果是则把 false 改成 true
    public static final boolean isMysql8 = false; // 是否为mysql8
    public static Connection conn = null;
    /**
     * 创建类时即连接数据库
     */
    public CommDAO() {
        conn = this.getConn();
    }
    /**
     * 数据库链接类
     * @return
     */
    public static Connection getConn() {
        try {
            if (conn == null || conn.isClosed()) {
                String connstr = getConnectString();
                conn = DriverManager.getConnection(connstr, username, pwd);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
    public static String getConnectString() {
        try {
            String connstr;
            if (!isMysql8) {
                Class.forName("com.mysql.jdbc.Driver");
                connstr = String.format("jdbc:mysql://localhost:3306/%s?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true", database);
            } else {
                Class.forName("com.mysql.cj.jdbc.Driver");
                connstr =
                    String.format(
                        "jdbc:mysql://localhost:3306/%s?useUnicode=true&characterEncoding=UTF-8&useSSL=FALSE&serverTimezone=UTC&useOldAliasMetadataBehavior=true",
                        database
                    );
            }
            return connstr;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
     * 根据表ID 获取数据
     * @param id   数值
     * @param table 表名称
     * @return
     */
    public HashMap getmap(String id, String table) {
        List<HashMap> list = new ArrayList();
        try {
            Statement st = conn.createStatement();
            //System.out.println("select * from "+table+" where id="+id);
            ResultSet rs = st.executeQuery("select * from " + table + " where id=" + id);
            ResultSetMetaData rsmd = rs.getMetaData();
            while (rs.next()) {
                HashMap map = new HashMap();
                int i = rsmd.getColumnCount();
                for (int j = 1; j <= i; j++) {
                    if (!rsmd.getColumnName(j).equals("ID")) {
                        String str = rs.getString(j) == null ? "" : rs.getString(j);
                        if (str.equals("null")) str = "";
                        map.put(rsmd.getColumnName(j), str);
                    } else map.put("id", rs.getString(j));
                }
                list.add(map);
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list.get(0);
    }
    /**
     * 根据sql 语句获取一行数据
     * @param sql
     * @return
     */
    public HashMap find(String sql) {
        HashMap map = new HashMap();
        //List<HashMap> list = new ArrayList();
        try {
            Statement st = conn.createStatement();
            System.out.println(sql);
            ResultSet rs = st.executeQuery(sql);
            ResultSetMetaData rsmd = rs.getMetaData();
            while (rs.next()) {
                //HashMap map = new HashMap();
                int i = rsmd.getColumnCount();
                for (int j = 1; j <= i; j++) {
                    if (!rsmd.getColumnName(j).equals("ID")) {
                        String str = rs.getString(j) == null ? "" : rs.getString(j);
                        if (str.equals("null")) str = "";
                        map.put(rsmd.getColumnName(j), str);
                    } else map.put("id", rs.getString(j));
                }
                //list.add(map);
                break;
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            int code = e.getErrorCode();
            String message = e.getMessage();
            System.err.println("SQL execute Error");
            System.err.println("code:" + code);
            System.err.println("Message:" + message);
        }
        return map;
    }
    /**
     * 根据某字段的值获取一行数据
     * @param nzd  字段名称
     * @param zdz  条件值
     * @param table  表
     * @return
     */
    public HashMap getmaps(String nzd, String zdz, String table) {
        List<HashMap> list = new ArrayList();
        try {
            Statement st = conn.createStatement();
            //System.out.println("select * from "+table+" where "+nzd+"='"+zdz+"'");
            ResultSet rs = st.executeQuery("select * from " + table + " where " + nzd + "='" + zdz + "'");
            ResultSetMetaData rsmd = rs.getMetaData();
            while (rs.next()) {
                HashMap map = new HashMap();
                int i = rsmd.getColumnCount();
                for (int j = 1; j <= i; j++) {
                    if (!rsmd.getColumnName(j).equals("ID")) {
                        String str = rs.getString(j) == null ? "" : rs.getString(j);
                        if (str.equals("null")) str = "";
                        map.put(rsmd.getColumnName(j), str);
                    } else map.put("id", rs.getString(j));
                }
                list.add(map);
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list.get(0);
    }
    /**
     * 获取前台提交的数据将数据写成Map<String , String> 形式,方便写入数据库
     * @param request
     * @return 返回值类型为Map<String, String>
     */
    public static HashMap getParameterStringMap(HttpServletRequest request) {
        Map<String, String[]> properties = request.getParameterMap(); //把请求参数封装到Map<String, String[]>中
        HashMap returnMap = new HashMap<String, String>();
        String name = "";
        String value = "";
        for (Map.Entry<String, String[]> entry : properties.entrySet()) {
            name = entry.getKey();
            String[] values = entry.getValue();
            if (null == values) {
                value = "";
            } else {
                value = StringUtil.join(",", values); //用于请求参数中请求参数名唯一
            }
            returnMap.put(name, value);
        }
        return returnMap;
    }
    /**
     * 插入数据库
     * @param request
     * @param tablename
     * @param extmap
     * @return
     */
    public String insert(HttpServletRequest request, String tablename, HashMap extmap) {
        extmap.put("addtime", Info.getDateStr()); // 设置添加时间为当前时间
        Query query = new Query(tablename); // 新建查询模块
        HashMap post = getParameterStringMap(request); // 获取前台提交的数据将数据写成Map对象
        post.putAll(extmap); //  扩展的数据以覆盖方式写到提交的数据中
        return query.add(post); // 将数据生成sql insert语句,并执行,可以查看输出控制台中执行的SQL语句
    }
    /**
     * 删除数据
     * @param request
     * @param tablename 表名称
     */
    public void delete(HttpServletRequest request, String tablename) {
        int i = 0;
        try {
            String did = request.getParameter("did");
            if (did == null) did = request.getParameter("scid");
            if (did == null) did = request.getParameter("id");
            if (did != null) {
                if (did.length() > 0) {
                    Statement st = conn.createStatement();
                    System.out.println("delete from " + tablename + " where id=" + did);
                    st.execute("delete from " + tablename + " where id=" + did);
                    st.close();
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            int code = e.getErrorCode();
            String message = e.getMessage();
            System.err.println("SQL execute Error");
            System.err.println("code:" + code);
            System.err.println("Message:" + message);
        }
    }
    /**
     * 获取某表一列数据
     * @param table
     * @return
     */
    public String getCols(String table) {
        String str = "";
        Connection conn = this.getConn();
        try {
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("select * from " + table);
            ResultSetMetaData rsmd = rs.getMetaData();
            int i = rsmd.getColumnCount();
            for (int j = 2; j <= i; j++) {
                str += rsmd.getColumnName(j) + ",";
            }
        } catch (SQLException e) {
            int code = e.getErrorCode();
            String message = e.getMessage();
            System.err.println("SQL execute Error");
            System.err.println("code:" + code);
            System.err.println("Message:" + message);
            //e.printStackTrace();
        }
        str = str.substring(0, str.length() - 1);
        return str;
    }
    /**
     * 更新数据
     * @param request
     * @param tablename
     * @param extmap
     * @return
     */
    public String update(HttpServletRequest request, String tablename, HashMap extmap) {
        Query query = new Query(tablename);
        HashMap post = getParameterStringMap(request);
        post.putAll(extmap);
        if (query.save(post)) {
            return String.valueOf(post.get("id"));
        }
        return "";
    }
    /**
     * 执行sql 语句
     * @param sql
     * @return
     */
    public long commOper(String sql) {
        System.out.println(sql);
        long autoInsertId = -1;
        try {
            Statement st = conn.createStatement();
            st.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
            ResultSet rs = st.getGeneratedKeys();
            while (rs.next()) {
                autoInsertId = rs.getLong(1);
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            int code = e.getErrorCode();
            String message = e.getMessage();
            System.err.println("SQL execute Error");
            System.err.println("code:" + code);
            System.err.println("Message:" + message);
        }
        return autoInsertId;
    }
    /**
     * 执行多条SQL语句
     * @param sql
     */
    public void commOperSqls(ArrayList<String> sql) {
        try {
            conn.setAutoCommit(false);
            for (int i = 0; i < sql.size(); i++) {
                Statement st = conn.createStatement();
                System.out.println(sql.get(i));
                st.execute(sql.get(i));
                st.close();
            }
            conn.commit();
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                //e1.printStackTrace();
                int code = e1.getErrorCode();
                String message = e1.getMessage();
                System.err.println("SQL execute Error");
                System.err.println("code:" + code);
                System.err.println("Message:" + message);
            }
            e.printStackTrace();
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (SQLException e) {
                int code = e.getErrorCode();
                String message = e.getMessage();
                System.err.println("SQL execute Error");
                System.err.println("code:" + code);
                System.err.println("Message:" + message);
                //e.printStackTrace();
            }
        }
    }
    /**
     * 根据SQL语句获取数据行
     * @param sql
     * @return
     */
    public List select(String sql) {
        System.out.println(sql);
        List<HashMap> list = new ArrayList();
        try {
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            ResultSetMetaData rsmd = rs.getMetaData();
            while (rs.next()) {
                HashMap map = new HashMap();
                int i = rsmd.getColumnCount();
                for (int j = 1; j <= i; j++) {
                    if (!rsmd.getColumnName(j).equals("ID")) {
                        String str = rs.getString(j) == null ? "" : rs.getString(j);
                        if (str.equals("null")) str = "";
                        map.put(rsmd.getColumnName(j), str);
                    } else map.put("id", rs.getString(j));
                }
                list.add(map);
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            if (sql.equals("show tables")) list = select("select table_name from   INFORMATION_SCHEMA.tables"); else {
                int code = e.getErrorCode();
                String message = e.getMessage();
                System.err.println("SQL execute Error");
                System.err.println("code:" + code);
                System.err.println("Message:" + message);
            }
            //e.printStackTrace();
        }
        return list;
    }
    public void close() {}
    /**
     * 执行一条查询sql,以 List<hashmap> 的形式返回查询的记录,记录条数,和从第几条开始,由参数决定,主要用于翻页
     * pageno 页码  rowsize 每页的条数
     */
    public List select(String sql, int pageno, int rowsize) {
        List<HashMap> list = new ArrayList();
        List<HashMap> mlist = new ArrayList();
        try {
            list = this.select(sql);
            int min = (pageno - 1) * rowsize;
            int max = pageno * rowsize;
            for (int i = 0; i < list.size(); i++) {
                if (!(i < min || i > (max - 1))) {
                    mlist.add(list.get(i));
                }
            }
        } catch (RuntimeException re) {
            re.printStackTrace();
            throw re;
        }
        return mlist;
    }
    public static void main(String[] args) {}
}

五,相关作品展示

基于Java开发、Python开发、PHP开发、C#开发等相关语言开发的实战项目

基于Nodejs、Vue等前端技术开发的前端实战项目

基于微信小程序和安卓APP应用开发的相关作品

基于51单片机等嵌入式物联网开发应用

基于各类算法实现的AI智能应用

基于大数据实现的各类数据管理和推荐系统

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
前端开发 Java
[Web程序设计]实验: Servlet基础应用
[Web程序设计]实验: Servlet基础应用
333 0
|
监控 前端开发 JavaScript
在线教育系统|线上教学系统|基于Springboot+Vue+Nodejs实现在线教学平台系统
在线教育系统|线上教学系统|基于Springboot+Vue+Nodejs实现在线教学平台系统
213 1
|
缓存 PyTorch 数据处理
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
1260 0
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
|
6月前
|
JSON 搜索推荐 API
淘宝商品详情优惠券API接口全攻略
淘宝商品详情优惠券API接口助力电商精准营销。通过商品ID,开发者可精准检索与特定商品相关的优惠券信息,包括面额、使用门槛、领取条件、有效期等详细数据,并实时监测优惠券状态。此接口支持个性化筛选参数,如优惠券面额范围和类型,返回JSON格式的优惠券列表及状态信息,满足数据整合、营销活动策划等需求,提升用户体验和运营效率。示例代码展示了Python调用方法,帮助快速集成。 供稿者:Taobaoapi2014
|
11月前
|
机器学习/深度学习 算法 Python
深度解析机器学习中过拟合与欠拟合现象:理解模型偏差背后的原因及其解决方案,附带Python示例代码助你轻松掌握平衡技巧
【10月更文挑战第10天】机器学习模型旨在从数据中学习规律并预测新数据。训练过程中常遇过拟合和欠拟合问题。过拟合指模型在训练集上表现优异但泛化能力差,欠拟合则指模型未能充分学习数据规律,两者均影响模型效果。解决方法包括正则化、增加训练数据和特征选择等。示例代码展示了如何使用Python和Scikit-learn进行线性回归建模,并观察不同情况下的表现。
1502 3
|
存储 Cloud Native API
Docker镜像管理:为什么Harbor是首选
Docker镜像管理:为什么Harbor是首选
XMind2022最新版破解激活教程,亲测可用
Xmind 是一款 全功能 的思维导图和头脑风暴软件。像大脑的瑞士军刀一般,助你理清思路,捕捉创意。
14687 1
|
运维 监控 API
自动化运维实践指南:Python脚本优化服务器管理任务
本文探讨了Python在自动化运维中的应用,介绍了使用Python脚本优化服务器管理的四个关键步骤:1) 安装必备库如paramiko、psutil和requests;2) 使用paramiko进行远程命令执行;3) 利用psutil监控系统资源;4) 结合requests自动化软件部署。这些示例展示了Python如何提升运维效率和系统稳定性。
861 8
|
机器学习/深度学习 人工智能 语音技术
情感识别与表达:FunAudioLLM的情感智能技术
【8月更文第28天】随着人工智能的发展,语音交互系统越来越普遍。其中,情感智能技术成为提高用户体验的关键因素之一。本文将探讨 FunAudioLLM 如何利用情感识别和表达技术来增强语音交互的真实感,并提供具体的代码示例。
1186 0
|
缓存 JavaScript 前端开发
从入门到项目实战 - Vue生命周期解析(vue2 与 vue3 比较)
从入门到项目实战 - Vue生命周期解析(vue2 与 vue3 比较)
388 0