欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java实战花店商城系统的实现流程

程序员文章站 2022-06-24 17:59:33
一、项目简述本系统功能包括:商品的分类展示,用户的注册登录,购物车,订单结算,购物车加减,后台商品管理,分类管理,订单管理等等功能。二、项目运行环境配置:jdk1.8 + tomcat8.5 + my...

一、项目简述

本系统功能包括:

商品的分类展示,用户的注册登录,购物车,订单结算,购物车加减,后台商品管理,分类管理,订单管理等等功能。

二、项目运行

环境配置:

jdk1.8 + tomcat8.5 + mysql + hbuilderx(webstorm也行)+ eclispe(intellij idea,eclispe,myeclispe,sts都支持)。

项目技术:

springboot + maven + mybatis+ vue 等等组成,b/s模式 + maven管理等等。

Java实战花店商城系统的实现流程

Java实战花店商城系统的实现流程

Java实战花店商城系统的实现流程

Java实战花店商城系统的实现流程

Java实战花店商城系统的实现流程

Java实战花店商城系统的实现流程

用户管理控制层:

/**
 * 用户
 **/
@restcontroller
@requestmapping("user")
public class usercontroller {
    @autowired
    userservice userservice;
    @autowired
    userdao dao;
 
    @requestmapping("/test")
    r test() {
        r r = new r();
        return r.setcode(4000).setmsg(constant.img_path).setdata(dao.findall());
    }
 
    @requestmapping("/queryinfobyaccount")
    r queryinfobyaccount(@requestparam("account") string account) {
        r r = new r();
        if (stringutil.isempty(account)){
            return r.setcode(4000).setmsg(httpmsg.invalid_param);
        }
        user loginuser = userservice.queryinfo(account);
        if (loginuser == null){
            return r.setcode(4000).setmsg(httpmsg.invalid_user);
        }
        return r.setcode(2000).setdata(loginuser);
    }
 
 
    @requestmapping("/find")
    r find(@requestparam("page") int page, @requestparam("searchkey") string searchkey) {
        r r = new r();
        map<string, object> map = new hashmap<>();
        list<user> users = userservice.find(searchkey);
        if (users == null) {
            return r.setcode(2000);
        }
        list<user> items = users.size() >= page * constant.page_size ?
                users.sublist((page - 1) * constant.page_size, page * constant.page_size)
                : users.sublist((page - 1) * constant.page_size, users.size());
        int len = users.size() % constant.page_size == 0 ? users.size() / constant.page_size
                : (users.size() / constant.page_size + 1);
        map.put("items", items);
        map.put("len", len);
        return r.setcode(2000).setdata(map);
    }
 
 
    @requestmapping("/create")
    r create(@requestbody user user) {
        r r = new r();
        int ans = userservice.add(user);
        if (ans == 1) {
            return r.setcode(2000).setmsg(httpmsg.add_user_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.add_user_failed);
    }
 
    @requestmapping("/update")
    r update(@requestbody user user) {
        r r = new r();
        int ans = userservice.update(user);
        if (ans >= 0) {
            return r.setcode(2000).setmsg(httpmsg.update_user_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.update_user_failed);
    }
 
 
    @deletemapping("/delete")
    r delete(@requestparam("id") int id) {
        r r = new r();
        int ans = userservice.delete(id);
        if (ans == 1) {
            return r.setcode(2000).setmsg(httpmsg.delete_user_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.delete_user_failed);
    }
}
 

订单管理控制层:

/**
 * 用户
 **/
@restcontroller
@requestmapping("order")
public class ordercontroller {
    @autowired
    orderservice orderservice;
    @autowired
    userdao userdao;
    @autowired
    orderdao orderdao;
    @autowired
    flowersdao flowersdao;
 
    @requestmapping("/test")
    r test() {
        r r = new r();
        return r.setcode(4000).setmsg(constant.img_path).setdata(orderdao.findall(null));
    }
 
    @requestmapping("/querybyaccount")
    r querybyaccount(@requestparam("account") string account) {
        r r = new r();
        if (stringutil.isempty(account)) {
            return r.setcode(4000).setmsg(httpmsg.invalid_param);
        }
        list<order> orders = orderservice.querybyaccount(account);
        return r.setcode(2000).setdata(orders);
    }
 
    @requestmapping("/find")
    r find(@requestparam("page") int page, @requestparam("searchkey") string searchkey, @requestparam("account") string account) {
        r r = new r();
        map<string, object> map = new hashmap<>();
        list<order> orders = orderservice.find(searchkey, account);
        if (orders == null) {
            return r.setcode(2000);
        }
        map.put("items", orders);
        map.put("len", orders.size());
        return r.setcode(2000).setdata(map);
    }
 
    @requestmapping("/findall")
    r findall(@requestparam("page") int page, @requestparam("searchkey") string searchkey) {
        r r = new r();
        map<string, object> map = new hashmap<>();
        list<order> orders = orderservice.findall(searchkey);
        if (orders == null) {
            return r.setcode(2000);
        }
        list<order> items = orders.size() >= page * constant.page_size ?
                orders.sublist((page - 1) * constant.page_size, page * constant.page_size)
                : orders.sublist((page - 1) * constant.page_size, orders.size());
        int len = orders.size() % constant.page_size == 0 ? orders.size() / constant.page_size
                : (orders.size() / constant.page_size + 1);
        list<ordervo> vos = new arraylist<>();
        for (order item : items) {
            user user = userdao.querybyid(item.getuid());
            ordervo vo = new ordervo();
            vo.setaddress(user.getaddress()).setphone(user.getphone()).setusername(user.getname())
                    .setamount(item.getamount()).setflower(item.getflower()).setid(item.getid())
                    .setuid(item.getuid()).setorder_guid(item.getorder_guid()).setprice(item.getprice())
                    .setstate(item.getstate());
            vos.add(vo);
        }
        map.put("items", vos);
        map.put("len", len);
        return r.setcode(2000).setdata(map);
    }
 
    @requestmapping("/update")
    r update(@requestbody order order) {
        r r = new r();
        int ans = orderservice.update(order);
        if (ans >= 0) {
            return r.setcode(2000).setmsg(httpmsg.update_user_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.update_user_failed);
    }
 
    @requestmapping("/changestate")
    r changestate(@requestbody order order) {
        orderdao.changestate(order);
        return new r().setcode(2000).setmsg(httpmsg.update_order_ok);
    }
 
    @deletemapping("/delete")
    r delete(@requestparam("id") int id) {
        r r = new r();
        int ans = orderservice.delete(id);
        if (ans == 1) {
            return r.setcode(2000).setmsg(httpmsg.delete_user_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.delete_user_failed);
    }
}
 

购物车控制层:

/**
 * 用户
 **/
@restcontroller
@requestmapping("cart")
public class cartcontroller {
    @autowired
    cartservice cartservice;
    @autowired
    orderservice orderservice;
    @autowired
    cartdao dao;
    @autowired
    flowersdao flowersdao;
 
    @requestmapping("/test")
    r test() {
        r r = new r();
        return r.setcode(4000).setmsg(constant.img_path).setdata(dao.findall());
    }
 
    @requestmapping("/querybyaccount")
    r querybyaccount(@requestparam("account") string account) {
        r r = new r();
        if (stringutil.isempty(account)) {
            return r.setcode(4000).setmsg(httpmsg.invalid_param);
        }
        list<cart> carts = cartservice.querybyaccount(account);
        for (cart cart : carts) {
            float price = flowersdao.queryprice(cart.getfid());
            cart.setprice(cart.getamount() * price);
        }
        return r.setcode(2000).setdata(carts);
    }
 
 
    @requestmapping("/find")
    r find(@requestparam("page") int page, @requestparam("searchkey") string searchkey, @requestparam("account") string account) {
        r r = new r();
        map<string, object> map = new hashmap<>();
        list<cart> carts = cartservice.find(searchkey, account);
        if (carts == null) {
            return r.setcode(2000);
        }
        list<cart> items = carts.size() >= page * constant.page_size ?
                carts.sublist((page - 1) * constant.page_size, page * constant.page_size)
                : carts.sublist((page - 1) * constant.page_size, carts.size());
        int len = carts.size() % constant.page_size == 0 ? carts.size() / constant.page_size
                : (carts.size() / constant.page_size + 1);
        map.put("items", items);
        map.put("len", len);
        return r.setcode(2000).setdata(map);
    }
 
    @requestmapping("/buy")
    r buy(@requestparam("account") string account) {
        r r = new r();
        // 查该用户的购物车
        list<cart> carts = (list<cart>) querybyaccount(account).getdata();
        for (cart cart : carts) {
            // 增加订单数据
            orderservice.add(cart);
            // 删除购物车数据
            cartservice.delete(cart.getid());
        }
        return r.setcode(2000).setmsg(httpmsg.buy_ok);
    }
 
 
    @requestmapping("/create")
    r create(@requestbody cart cart) {
        r r = new r();
        int ans = cartservice.add(cart);
        if (ans == 1) {
            return r.setcode(2000).setmsg(httpmsg.add_cart_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.add_cart_failed);
    }
 
    @requestmapping("/update")
    r update(@requestbody cart cart) {
        r r = new r();
        int ans = cartservice.update(cart);
        if (ans >= 0) {
            return r.setcode(2000).setmsg(httpmsg.update_user_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.update_user_failed);
    }
 
 
    @deletemapping("/delete")
    r delete(@requestparam("id") int id) {
        r r = new r();
        int ans = cartservice.delete(id);
        if (ans == 1) {
            return r.setcode(2000).setmsg(httpmsg.delete_user_ok);
        }
        return r.setcode(4000).setmsg(httpmsg.delete_user_failed);
    }
}
 

到此这篇关于java实战花店商城系统的实现流程的文章就介绍到这了,更多相关java  花店商城系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!