Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)

发布时间:2024-09-28 12:01

源码获取:俺的博客首页 \"资源\" 里下载!

项目介绍

本项目分为前后台,且有普通用户与管理员两种角色。
用户角色包含以下功能:
用户登录,查看首页,按分类查看商品,查看新闻资讯,查看关于我们,查看商品详情,加入购物车,查看我的订单,提交订单,添加收获地址,支付订单等功能。
管理员角色包含以下功能:
管理员登录,会员管理,资讯管理,类别管理,商品管理,商品库存管理,订单管理,售后管理,留言管理,顾客活跃度管理,营业额统计查看,销售量查看等功能。


环境需要

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项目:否;


技术栈

1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+bootstrap+jQuery


使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ssm_zxncpshop 登录

 \"Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)_第1张图片\"

 \"Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)_第2张图片\"

 \"Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)_第3张图片\"

 \"Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)_第4张图片\"

 \"Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)_第5张图片\"

 \"Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)_第6张图片\"

 \"Java项目:在线农产品商城(java+SSM+JSP+bootstrap+jQuery+mysql)_第7张图片\"

用户和管理员控制层:

/**
 * 用户和管理员控制层
 */
@Controller
public class UserController {
    @Resource(name = \"userService\")
    UserService userService;
    @Resource(name = \"goodsCarService\")
    GoodsCarService goodsCarService;
//    @Resource(name = \"goodsService\")
//    GoodsService goodsService;
    @Resource(name = \"orderService\")
    OrderService orderService;

    /**
     * 用户注册
     */
    @RequestMapping(\"/userRegister\")
    @ResponseBody
    public Map doReg(String username, String password, String email, HttpServletRequest request) {
        Map map = new HashMap();
        User u = userService.findUserByUsername(username);
        if (u != null) {
            map.put(\"status\", 1);
            map.put(\"message\", \"注册失败,该账户名已存在\");
        } else {
            String id = App.getUid();
            int dr = 0;
            User user = new User(id, username, password, dr, email);
            int result = userService.doReg(user);
            if (result == 1) {
                HttpSession session = request.getSession();
                session.setAttribute(\"username\", username);
                session.setAttribute(\"email\", email);
                map.put(\"status\", 0);
                map.put(\"message\", \"注册成功\");
            }
        }
        return map;
    }

    /**
     * 用户登录
     * checked 为1 代表记住用户名,为0 代表忘记用户名
     */
    @RequestMapping(\"/userLogin\")
    @ResponseBody
    public Map doLogin(String username, String pwd, String checkcode, int checked, HttpServletRequest request) {
        Map map = new HashMap();
        HttpSession session = request.getSession();
        String checkcode_server = (String) session.getAttribute(\"CHECKCODE\");
        session.removeAttribute(\"CHECKCODE\");//为了保证验证码只能使用一次
        User u = userService.findUserByUsername(username);
        if (u == null || u.getDr() == 1) {
            map.put(\"status\", 1);
            map.put(\"message\", \"登录失败,请检查信息是否正确\");
        } else {
            if (u.getPassword().equals(pwd) && checkcode.equalsIgnoreCase(checkcode_server)) {
                String userid = u.getId();
                List goodscars = goodsCarService.findGoodscarByUserId(userid);
                App.goodscarList = goodscars;
                session.setAttribute(\"goodscarList\", App.goodscarList);
                session.setAttribute(\"count\", App.goodscarList.size());
                session.setAttribute(\"username\", username);
                session.setAttribute(\"email\", u.getEmail());
                List orders = new ArrayList();
                List ordersEndList = orderService.ordersEndListById(userid);
                if (ordersEndList.size()>0){
                    session.setAttribute(\"ordersEndListById\",ordersEndList);
                }
                List gcs = orderService.selectOrderByuserId(u.getId());
                for (Ordergoods gs : gcs) {
                    orders.add(gs);
                }
                if (orders.size() > 0) {
                    session.setAttribute(\"orders\", orders);
                }
                if (checked == 1) {
                    App.USERNAME = username;
                } else if (checked == 0) {
                    App.USERNAME = null;
                }
                map.put(\"status\", 0);
                map.put(\"message\", \"登录成功\");
            } else {
                map.put(\"status\", 1);
                map.put(\"message\", \"登录失败,请检查信息是否正确\");
            }
        }
        return map;
    }

    /**
     * 管理员登录
     * checked 为 1 代表记住用户名和密码,为0 反之
     */
    @RequestMapping(\"/userAdminLogin\")
    @ResponseBody
    public Map adminLogin(String username, String password, int checked, HttpServletRequest request) {
        HttpSession session = request.getSession();
        Map map = new HashMap();
        User u = userService.findUserByUsername(username);
        if (u == null || u.getDr() == 0) {
            map.put(\"status\", 1);
            map.put(\"message\", \"登录失败,请检查信息是否正确\");
        } else {
            if (u.getPassword().equals(password)) {
                session.setAttribute(\"adminUsername\", username);
                session.setAttribute(\"adminEmail\", u.getEmail());
                if (checked == 1) {
                    App.ADMIN_USERNAME = username;
                    App.ADMIN_PASSWORD = password;
                } else if (checked == 0) {
                    App.ADMIN_USERNAME = null;
                    App.ADMIN_PASSWORD = null;
                }
                map.put(\"status\", 0);
                map.put(\"message\", \"登录成功\");
            } else {
                map.put(\"status\", 1);
                map.put(\"message\", \"登录失败,请检查信息是否正确\");
            }
        }
        return map;
    }

    /**
     * 管理员修改密码
     */
    @RequestMapping(\"/userAdminForgetPwd\")
    @ResponseBody
    public Map adminForgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {
        Map map = new HashMap();
        HttpSession session = request.getSession();
        String checkcode_server = (String) session.getAttribute(\"CHECKCODE\");
        session.removeAttribute(\"CHECKCODE\");//为了保证验证码只能使用一次
        User u = userService.findUserByUsername(username);
        if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 1) {
            User user = new User(username, password);
            int result = userService.updatePassword(user);
            if (result == 1) {
                map.put(\"status\", 0);
                map.put(\"message\", \"修改成功\");
            } else {
                map.put(\"status\", 1);
                map.put(\"message\", \"修改失败,请检查信息是否正确\");
            }
        } else {
            map.put(\"status\", 1);
            map.put(\"message\", \"修改失败,请检查信息是否正确\");
        }
        return map;
    }

    /**
     * 用户修改密码
     */
    @RequestMapping(\"/userForgetPwd\")
    @ResponseBody
    public Map forgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {
        Map map = new HashMap();
        HttpSession session = request.getSession();
        String checkcode_server = (String) session.getAttribute(\"CHECKCODE\");
        session.removeAttribute(\"CHECKCODE\");//为了保证验证码只能使用一次
        User u = userService.findUserByUsername(username);
        if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 0) {
            User user = new User(username, password);
            int result = userService.updatePassword(user);
            if (result == 1) {
                map.put(\"status\", 0);
                map.put(\"message\", \"修改成功\");
            } else {
                map.put(\"status\", 1);
                map.put(\"message\", \"修改失败,请检查信息是否正确\");
            }
        } else {
            map.put(\"status\", 1);
            map.put(\"message\", \"修改失败,请检查信息是否正确\");
        }
        return map;
    }

    /**
     * 用户退出
     */
    @RequestMapping(\"/userQuit\")
    public String userQuit(HttpServletRequest request){
        HttpSession session = request.getSession();
        String auname = (String) session.getAttribute(\"adminUsername\");
        if (auname == null){
            session.invalidate();
            App.goodscarList = null;
            App.ADDRESS = null;
            HttpSession session1 = request.getSession();
            session1.setAttribute(\"saveUsername\", App.USERNAME);
        }else {
            session.removeAttribute(\"username\");
            session.removeAttribute(\"saveUsername\");
            session.removeAttribute(\"email\");
            session.removeAttribute(\"goodsBrowse\");
            session.removeAttribute(\"goodscarList\");
            session.removeAttribute(\"count\");
            session.removeAttribute(\"goodscarCount\");
            session.removeAttribute(\"orders\");
            session.removeAttribute(\"ordersEndListById\");
            App.goodscarList = null;
            App.ADDRESS = null;
            session.setAttribute(\"saveUsername\", App.USERNAME);
        }
        return \"redirect:toIndex\";
    }

    /**
     * 管理员退出
     */
    @RequestMapping(\"/userAdminQuit\")
    public String userAdminQuit(HttpServletRequest request){
        HttpSession session = request.getSession();
//        session.invalidate();
        session.removeAttribute(\"adminUsername\");
        session.removeAttribute(\"adminEmail\");
        session.removeAttribute(\"saveadminUsername\");
        session.removeAttribute(\"saveadminPassword\");
        session.removeAttribute(\"ordersList\");
        session.removeAttribute(\"ordersWaitList\");
        session.removeAttribute(\"ordersEndList\");
        session.setAttribute(\"saveadminUsername\", App.ADMIN_USERNAME);
        session.setAttribute(\"saveadminPassword\", App.ADMIN_PASSWORD);
        return \"redirect:toAdminLogin\";
    }
}

购物车管理控制层:

@Controller
public class GoodsCarController {
    @Resource(name = \"goodsCarService\")
    GoodsCarService goodsCarService;
    @Resource(name = \"userService\")
    UserService userService;
    @Resource(name = \"orderService\")
    OrderService orderService;

    /**
     * 加入购物车
     */
    @RequestMapping(\"/addGoodsCar\")
    @ResponseBody
    public Map addGoodsCar(String goodsid, String shuliang, HttpServletRequest request) {
        Map map = new HashMap();
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute(\"username\");
        User u = userService.findUserByUsername(username);
        String userid = u.getId();
        List goodscars = goodsCarService.findGoodscarByUserId(userid);
        for (Goodscar gs : goodscars) {
            if (gs.getGoodsid().equals(goodsid)){
                double count = Double.parseDouble(shuliang);
                count += gs.getCount();
                Map map1 = new HashMap();
                int reserved1 = (int) count;
                map1.put(\"count\",count);
                map1.put(\"goodsid\",goodsid);
                map1.put(\"reserved1\",String.valueOf(reserved1));
                int result = goodsCarService.updateGoodsCarByCount(map1);
                if (result == 1){
                    List gds = goodsCarService.findGoodscarByUserId(userid);
                    App.goodscarList = gds;
                    session.setAttribute(\"goodscarList\", App.goodscarList);
                    session.setAttribute(\"count\", App.goodscarList.size());
                    map.put(\"status\", 0);
                    map.put(\"message\", \"加入购物车成功\");
                }else {
                    map.put(\"status\", 1);
                    map.put(\"message\", \"加入购物车失败\");
                }
                return map;
            }
        }
        String id = App.getUid();
        int dr = 1;
        double count = Double.parseDouble(shuliang);
        Map map1 = new HashMap();
        map1.put(\"id\",id);
        map1.put(\"goodsid\",goodsid);
        map1.put(\"userid\",userid);
        map1.put(\"dr\",dr);
        map1.put(\"count\",count);
        map1.put(\"reserved1\",shuliang);
        int result = goodsCarService.addGoodsCar(map1);
        if (result == 1) {
            List gods = goodsCarService.findGoodscarByUserId(userid);
            App.goodscarList = gods;
            session.setAttribute(\"goodscarList\", App.goodscarList);
            session.setAttribute(\"count\", App.goodscarList.size());
            map.put(\"status\", 0);
            map.put(\"message\", \"加入购物车成功\");
        } else {
            map.put(\"status\", 1);
            map.put(\"message\", \"加入购物车失败\");
        }
        return map;
    }

    /**
     * 购物车的商品单个逻辑删除
     */
    @RequestMapping(\"/goodscarDelete\")
    @ResponseBody
    public Map goodscarDelete(String id, HttpServletRequest request) {
        Map map = new HashMap();
        int result = goodsCarService.goodsDelete(id);
        if (result == 1) {
            HttpSession session = request.getSession();
            String username = (String) session.getAttribute(\"username\");
            User u = userService.findUserByUsername(username);
            List goodscars = goodsCarService.findGoodscarByUserId(u.getId());
            App.goodscarList = goodscars;
            session.setAttribute(\"goodscarList\", App.goodscarList);
            session.setAttribute(\"count\", App.goodscarList.size());
            map.put(\"status\", 0);
            map.put(\"message\", \"删除成功\");
        } else {
            map.put(\"status\", 1);
            map.put(\"message\", \"删除失败\");
        }
        return map;
    }

    /**
     * 结算商品
     */
    @RequestMapping(\"/totalAllGoods\")
    @ResponseBody
    public Map totalAllGoods(String ids,String reserved1s, HttpServletRequest request) {
        Map map = new HashMap();
        HttpSession session = request.getSession();
        String[] gcids = ids.split(\",\");
        String[] resves = reserved1s.split(\",\");
        Map map3 = new HashMap();
        for (int i=0;i goodscars = goodsCarService.findGoodscarDrById(gcids);
            List orders = new ArrayList();
            Map map1 = new HashMap();
            for (Goodscar gc : goodscars) {
                String id = App.getUid();
                String uid = gc.getUserid();
                String gid = gc.getGoodsid();
                String gcid = gc.getId();
                int dr = gc.getDr();
                map1.put(\"id\",id);
                map1.put(\"userid\",uid);
                map1.put(\"goodsid\",gid);
                map1.put(\"goodscarid\",gcid);
                map1.put(\"dr\",dr);
                orderService.addOrdergoods(map1);
            }
            List gcs = orderService.selectOrderByuserId(u.getId());
            for (Ordergoods gs : gcs) {
                orders.add(gs);
            }
            if (orders.size() <= 0) {
                map.put(\"status\", 1);
                map.put(\"message\", \"交易失败\");
            } else {
                session.setAttribute(\"orders\", orders);
                String userid = u.getId();
                List gc = goodsCarService.findGoodscarByUserId(userid);
                App.goodscarList = gc;
                session.setAttribute(\"goodscarList\", App.goodscarList);
                session.setAttribute(\"count\", App.goodscarList.size());
                map.put(\"status\", 0);
                map.put(\"message\", \"交易成功\");
            }
        }
        return map;
    }

    /**
     * 立即购买
     */
    @RequestMapping(\"/buyGoodsImmediately\")
    @ResponseBody
    public Map buyGoodsImmediately(String goodsid, String shuliang,HttpServletRequest request){
        Map map = new HashMap();
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute(\"username\");
        User u = userService.findUserByUsername(username);
        String userid = u.getId();
        String id = App.getUid();
        int dr = 0;
        double count = Double.parseDouble(shuliang);
        Map map1 = new HashMap();
        map1.put(\"id\",id);
        map1.put(\"goodsid\",goodsid);
        map1.put(\"userid\",userid);
        map1.put(\"dr\",dr);
        map1.put(\"count\",count);
        map1.put(\"reserved1\",shuliang);
        int result = goodsCarService.addGoodsCar(map1);
        Map map2 = new HashMap();
        map2.put(\"id\",App.getUid());
        map2.put(\"userid\",userid);
        map2.put(\"goodsid\",goodsid);
        map2.put(\"goodscarid\",id);
        map2.put(\"dr\",dr);
        int result2 = orderService.addOrdergoods(map2);
        if (result == 1 && result2 == 1){
            List orders = new ArrayList();
            List gcs = orderService.selectOrderByuserId(u.getId());
            for (Ordergoods gs : gcs) {
                orders.add(gs);
            }
            session.setAttribute(\"orders\", orders);
            map.put(\"status\", 0);
            map.put(\"message\", \"购买成功\");
            map.put(\"result\",id);
        }else {
            map.put(\"status\", 1);
            map.put(\"message\", \"购买失败\");
            map.put(\"result\",null);
        }
        return map;
    }
}

订单管理控制层: 

@Controller
public class OrdergoodsController {
    @Resource(name = \"orderService\")
    OrderService orderService;
    @Resource(name = \"userService\")
    UserService userService;
    @Resource(name = \"goodsCarService\")
    GoodsCarService goodsCarService;
    @Resource(name = \"goodsService\")
    GoodsService goodsService;

    /**
     * 取消订单
     */
    @RequestMapping(\"/cancelOrder\")
    @ResponseBody
    public synchronized Map cancelOrder(String id,String username, HttpServletRequest request) {
        Map map = new HashMap();
        User us = userService.findUserByUsername(username);
        Ordergoods ordergoods = orderService.selectGoodsId(id);
        if (us.getDr() == 1){
            //管理员确定订单
            if (ordergoods != null && ordergoods.getDr() != 1){
                int result = orderService.orderEnsure(id);
                Ordergoods og = orderService.selectOrderById(id);
                Map map2 = new HashMap();
                double count = (og.getGoods().getCount()-og.getGoodscar().getCount());
                map2.put(\"id\",og.getGoods().getId());
                map2.put(\"count\",count);
                int result1 = goodsService.updateGoodsCount(map2);
                if (result==1 && result1==1){
                    HttpSession session = request.getSession();
                    List ordersWaitList = orderService.ordersWaitList();
                    session.setAttribute(\"ordersWaitList\",ordersWaitList);
                    map.put(\"status\", 0);
                    map.put(\"message\", \"发货成功\");
                }else {
                    map.put(\"status\", 1);
                    map.put(\"message\", \"发货失败\");
                }
            }else {
                map.put(\"status\", 1);
                map.put(\"message\", \"发货失败\");
            }
        }else {
            //用户确定订单
            if (ordergoods != null && ordergoods.getDr() != 3){
                int result = orderService.cancelOrder(id);
                if (result == 1) {
                    Ordergoods or = orderService.selectGoodsId(id);
                    String goodscar_id = or.getGoodscarid();
                    int info = goodsCarService.updateGoodscarDr(goodscar_id);
                    if (info == 1) {
                        HttpSession session = request.getSession();
                        String uname = (String) session.getAttribute(\"username\");
                        User u = userService.findUserByUsername(uname);
                        List orders = new ArrayList();
                        List gcs = orderService.selectOrderByuserId(u.getId());
                        for (Ordergoods gs : gcs) {
                            orders.add(gs);
                        }
                        session.setAttribute(\"orders\", orders);
                        List goodscars = goodsCarService.findGoodscarByUserId(u.getId());
                        App.goodscarList = goodscars;
                        session.setAttribute(\"goodscarList\", App.goodscarList);
                        session.setAttribute(\"count\", App.goodscarList.size());
                        map.put(\"status\", 0);
                        map.put(\"message\", \"订单取消成功\");
                        return map;
                    }
                }
            }
            map.put(\"status\", 1);
            map.put(\"message\", \"订单取消失败\");
        }
        return map;
    }

    /**
     * 添加地址
     */
    @RequestMapping(\"/addressOver\")
    @ResponseBody
    public Map addressOver(String address, String ids, HttpServletRequest request) {
        Map map = new HashMap();
        String[] gcids = ids.split(\",\");
        Map map1 = new HashMap();
        map1.put(\"address\",address);
        map1.put(\"gcids\",gcids);
        int result = orderService.addAddress(map1);
        if (result <= 0){
            map.put(\"status\", 1);
            map.put(\"message\", \"添加地址失败\");
        }else {
            App.ADDRESS = address;
            HttpSession session = request.getSession();
            session.setAttribute(\"address\",App.ADDRESS);
            map.put(\"status\", 0);
            map.put(\"message\", \"添加地址成功\");
        }
        return map;
    }

    /**
     * 全部的订单列表
     */
    @RequestMapping(\"/ordersList\")
    @ResponseBody
    public Map ordersList(HttpServletRequest request){
        Map map = new HashMap();
        HttpSession session = request.getSession();
        List ordersList = orderService.ordersList();
        if (ordersList.size()<=0){
            map.put(\"status\", 1);
            map.put(\"message\", \"暂无订单\");
        }else {
            session.setAttribute(\"ordersList\",ordersList);
            map.put(\"status\", 0);
            map.put(\"message\", \"订单查询成功\");
        }
        return map;
    }

    /**
     * 待发货的订单
     */
    @RequestMapping(\"/ordersWaitList\")
    @ResponseBody
    public Map ordersWaitList(HttpServletRequest request){
        Map map = new HashMap();
        HttpSession session = request.getSession();
        List ordersWaitList = orderService.ordersWaitList();
        if (ordersWaitList.size()<=0){
            session.setAttribute(\"ordersWaitList\",ordersWaitList);
            map.put(\"status\", 1);
            map.put(\"message\", \"暂无订单\");
        }else {
            session.setAttribute(\"ordersWaitList\",ordersWaitList);
            map.put(\"status\", 0);
            map.put(\"message\", \"订单查询成功\");
        }
        return map;
    }

    /**
     * 已发货的订单
     */
    @RequestMapping(\"/ordersEndList\")
    @ResponseBody
    public Map ordersEndList(HttpServletRequest request){
        Map map = new HashMap();
        HttpSession session = request.getSession();
        List ordersEndList = orderService.ordersEndList();
        if (ordersEndList.size()<=0){
            map.put(\"status\", 1);
            map.put(\"message\", \"暂无订单\");
        }else {
            session.setAttribute(\"ordersEndList\",ordersEndList);
            map.put(\"status\", 0);
            map.put(\"message\", \"订单查询成功\");
        }
        return map;
    }

//    /**
//     * 进行发货
//     */
//    @RequestMapping(\"/orderEnsure\")
//    @ResponseBody
//    public Map orderEnsure(String id,String reserved1,HttpServletRequest request){
//        Map map = new HashMap();
//        HttpSession session = request.getSession();
//        int result = orderService.orderEnsure(id);
//        if (result == 1){
//            map.put(\"status\", 0);
//            map.put(\"message\", \"发货成功\");
//        }else {
//            map.put(\"status\", 1);
//            map.put(\"message\", \"发货失败\");
//        }
//        return map;
//    }
}

源码获取:俺的博客首页 \"资源\" 里下载! 

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号