SSM框架(spring+springmvc+mybatis)+Mysql实现的网上订餐管理系统(功能包含前台:商品浏览、加入购物车、提交订单、订单详情、校园资讯 后台:订单管理、配送、角色管理等)

@

SSM框架(spring+springmvc+mybatis)+Mysql实现的网上订餐管理系统

本系统解决了一站式商品配送,网上订餐的难题,用户可以在前台浏览餐品、下单,后台可以进行订单管理配送,同时还有角色等的管理,前台还可以查看一些校园资讯内容,功能完备。

实现功能截图

前台
登录
请添加图片描述
前台首页
请添加图片描述
请添加图片描述
请添加图片描述

请添加图片描述
添加购物车
请添加图片描述
请添加图片描述
提交订单
请添加图片描述
订单信息填写
请添加图片描述
购物车信息
请添加图片描述
校园资讯
请添加图片描述
常见问题
请添加图片描述

后台:
登录
请添加图片描述
后台订单管理
请添加图片描述
订单详情
请添加图片描述
订单发货
请添加图片描述
评论管理
请添加图片描述
商品分类管理
请添加图片描述
商品列表
请添加图片描述

权限管理
请添加图片描述
角色管理
请添加图片描述
用户管理
请添加图片描述
资讯管理
请添加图片描述

系统功能

本网上订餐管理系统实现了以下功能:
前台:
1、登录
2、餐品浏览
3、加入购物车
4、购物车查看
5、下单
6、下单信息填写
7、校园资讯
后台:
8、登录
9、订单管理
10、订单详情查看
11、订单发货
12、用户管理
13、权限管理
14、角色管理
15、评论管理
18、商品管理

使用技术

数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:SSM框架(spring+springmvc+mybatis)

代码

实体类
Order.java

package com.byh.biyesheji.pojo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

/**
 * 公众号:程序猿矛盾体
 * 微信:Code2Life2
 */

@ToString
public class Order {

    private Integer id;

    private String code;//订单编号

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getCstid() {
        return cstid;
    }

    public void setCstid(Integer cstid) {
        this.cstid = cstid;
    }

    public List<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public float getTotal() {
        return total;
    }

    public void setTotal(float total) {
        this.total = total;
    }

    public int getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(int totalNumber) {
        this.totalNumber = totalNumber;
    }

    private String address;

    private Integer status;

    private Integer cstid;

    private List<OrderItem> orderItems;

    private Customer customer;

    private float total;  //总价

    private int totalNumber; //总数量

}

Product.java

package com.byh.biyesheji.pojo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 公众号:程序猿矛盾体
 * 微信:Code2Life2
 */
public class Product {
    private Integer id;

    private String name;

    private Float price;

    private Integer zan;

    private Integer number;

    private Integer status;

    private String imageurl;

    private String miaoshu;

    private Integer cid;

    private Long bid;

    private Category category;
    private User user;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public Integer getZan() {
        return zan;
    }

    public void setZan(Integer zan) {
        this.zan = zan;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getImageurl() {
        return imageurl;
    }

    public void setImageurl(String imageurl) {
        this.imageurl = imageurl;
    }

    public String getMiaoshu() {
        return miaoshu;
    }

    public void setMiaoshu(String miaoshu) {
        this.miaoshu = miaoshu;
    }

    public Integer getCid() {
        return cid;
    }

    public void setCid(Integer cid) {
        this.cid = cid;
    }

    public Long getBid() {
        return bid;
    }

    public void setBid(Long bid) {
        this.bid = bid;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", zan=" + zan +
                ", number=" + number +
                ", status=" + status +
                ", imageurl='" + imageurl + '\'' +
                ", miaoshu='" + miaoshu + '\'' +
                ", cid=" + cid +
                ", bid=" + bid +
                ", category=" + category +
                ", user=" + user +
                '}';
    }
}

service层
OrderServiceImpl.java

package com.byh.biyesheji.service.impl;

import com.byh.biyesheji.dao.OrderMapper;
import com.byh.biyesheji.pojo.Customer;
import com.byh.biyesheji.pojo.Order;
import com.byh.biyesheji.pojo.OrderExample;
import com.byh.biyesheji.pojo.OrderItem;
import com.byh.biyesheji.service.CustomerService;
import com.byh.biyesheji.service.OrderItemService;
import com.byh.biyesheji.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * 公众号:程序猿矛盾体
 * 微信:Code2Life2
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    CustomerService customerService;
    @Autowired
    OrderItemService orderItemService;

    @Override
    public void save(Order c) {
        orderMapper.insert(c);
    }

    @Override
    public void del(int id) {
        orderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Order c) {
        orderMapper.updateByPrimaryKeySelective(c);
    }

    @Override
    public Order get(int id) {
        return orderMapper.selectByPrimaryKey(id);
    }

    public List<Order> list(){
        OrderExample example =new OrderExample();
        example.setOrderByClause("id desc");
        List<Order> result =orderMapper.selectByExample(example);
        setCust(result);
        return result;
    }
    //给每个订单设置客户
    public void setCust(List<Order> os){
        for (Order o : os)
            setCust(o);
    }
    //给客户实体设置客户
    public void setCust(Order o){
        int cstid = o.getCstid();
        Customer customer = customerService.get(cstid);
        o.setCustomer(customer);
    }

    @Transactional(propagation= Propagation.REQUIRED,rollbackForClassName="Exception")
    @Override
    public float add(Order o, List<OrderItem> ois) {
        float total = 0;
        save(o);//新增订单数据

        if(false)
            throw new RuntimeException(); //用来模拟当增加订单后出现异常,观察事务管理是否预期发生。(需要把false修改为true才能观察到)

        for (OrderItem oi: ois) {
            oi.setOid(o.getId());//给订单项设置订单id 关联起来
            orderItemService.update(oi);
            total+=oi.getProduct().getPrice()*oi.getNumber();//商品的价格+当前订单项购买数量
        }
        return total;
    }

    @Override
    public List<Order> list(int cstid) {
        OrderExample example =new OrderExample();
        example.createCriteria().andCstidEqualTo(cstid);
        example.setOrderByClause("id asc");
        return orderMapper.selectByExample(example);
    }

}

ProductServiceImpl.java

package com.byh.biyesheji.service.impl;

import com.byh.biyesheji.dao.ProductMapper;
import com.byh.biyesheji.dao.UserMapper;
import com.byh.biyesheji.pojo.*;
import com.byh.biyesheji.service.CategoryService;
import com.byh.biyesheji.service.ProductService;
import com.byh.biyesheji.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 公众号:程序猿矛盾体
 * 微信:Code2Life2
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private UserService userService;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Product> list() {
        List<Product> products = productMapper.selectByExample(null);//获得商品列表
        for (Product p:products){
            Category category = categoryService.get(p.getCid());
            p.setCategory(category);
            User user = userService.get(p.getBid());
            p.setUser(user);
        }
        return products;
    }

    @Override
    public String enableStatus(String name) {
        productMapper.enableStatus(name);
        return "success";
    }

    @Override
    public String stopStatus(String name) {
        productMapper.stopStatus(name);
        return "success";
    }

    @Override
    public void save(Product product) {
        product.setStatus(1);
        productMapper.insert(product);
    }

    @Override
    public void setImageURL(ProductVO vo) {
        productMapper.setImageUrl(vo);
    }

    @Override
    public Product get(int id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public void del(int id) {
        productMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Category getCategoryByCid(int id) {
        Category category = categoryService.get(id);
        return category;
    }

    @Override
    public void update(Product product) {
        productMapper.updateByPrimaryKeySelective(product);
    }

    @Override
    public List<Product> getProductsByCid(Integer id) {
        ProductExample example = new ProductExample();
        example.createCriteria().andCidEqualTo(id).andStatusEqualTo(1);
        return productMapper.selectByExample(example);
    }

    @Override
    public User getUserByBid(long id) {
        return  userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Product> findByName(String pName) {
        ProductExample example = new ProductExample();
        example.createCriteria().andNameLike("%"+pName+"%");
        List<Product> products = productMapper.selectByExample(example);
        return products;
    }

    @Override
    public List<Product> findByCid(int cid) {
        ProductExample example = new ProductExample();
        example.createCriteria().andCidEqualTo(cid);
        List<Product> products = productMapper.selectByExample(example);
        return products;
    }

    @Override
    public boolean findProByCid(int cid) {
        ProductExample example = new ProductExample();
        example.createCriteria().andCidEqualTo(cid);
        List<Product> products = productMapper.selectByExample(example);
        return products.size()>0&&products!=null?true:false;
    }

}

controller层
OrderController.java

package com.byh.biyesheji.controller;


import com.byh.biyesheji.pojo.Order;
import com.byh.biyesheji.service.OrderItemService;
import com.byh.biyesheji.service.OrderService;
import com.byh.biyesheji.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 订单模块controller
 */
/**
 * 公众号:程序猿矛盾体
 * 微信:Code2Life2
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;
    @Autowired
    OrderItemService orderItemService;

    /**
     * 所有订单
     * @param model
     * @param page
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, Page page){
        PageHelper.offsetPage(page.getStart(),page.getCount());

        List<Order> os= orderService.list();

        int total = (int) new PageInfo<>(os).getTotal();
        page.setTotal(total);
        //为订单添加订单项数据
        orderItemService.fill(os);

        model.addAttribute("os", os);
        model.addAttribute("page", page);
        model.addAttribute("totals", total);

        return "ordermodule/order-list";
    }

    /**
     * 订单发货
     * @param o
     * @return
     */
    @RequestMapping("/orderDelivery")
    public String delivery(Order o){
        o.setStatus(2);
        orderService.update(o);
        return "redirect:list";
    }

    /**
     * 查看当前订单的订单项
     * @param oid
     * @param model
     * @return
     */
    @RequestMapping("/seeOrderItem")
    public String seeOrderItem(int oid,Model model){
        Order o = orderService.get(oid);
        orderItemService.fill(o);
        model.addAttribute("orderItems",o.getOrderItems());
        model.addAttribute("total",o.getOrderItems().size());
        model.addAttribute("totalPrice",o.getTotal());
        return "ordermodule/orderItem-list";
    }

}

ProductController.java

package com.byh.biyesheji.controller;

import com.byh.biyesheji.pojo.Category;
import com.byh.biyesheji.pojo.Product;
import com.byh.biyesheji.pojo.ProductVO;
import com.byh.biyesheji.pojo.User;
import com.byh.biyesheji.service.CategoryService;
import com.byh.biyesheji.service.ProductService;
import com.byh.biyesheji.service.UserService;
import com.byh.biyesheji.util.Page;
import com.byh.biyesheji.util.UploadUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * 商品模块controller
 */
/**
 * 公众号:程序猿矛盾体
 * 微信:Code2Life2
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;
    @Autowired
    private UserService userService;
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/list")
    public String list(Model model, Page page){
        PageHelper.offsetPage(page.getStart(),page.getCount());//分页查询
        List<Product> list= productService.list();
        int total = (int) new PageInfo<>(list).getTotal();//总条数
        page.setTotal(total);

        model.addAttribute("list",list);
        model.addAttribute("total",total);
        model.addAttribute("page", page);

        return "productmodule/product-list";
    }


    @RequestMapping("/enableStatus")
    @ResponseBody
    public String enableStatus(@RequestParam(value = "name") String name){
        return productService.enableStatus(name);
    }

    @RequestMapping("/stopStatus")
    @ResponseBody
    public String stopStatus(@RequestParam(value = "name") String name){
        return productService.stopStatus(name);
    }

    @RequestMapping("/productAddUI")
    public String addUI(Model model){

        List<Category> categoryList = categoryService.list();

        List<User> userList = userService.list();

        model.addAttribute("categoryList",categoryList);
        model.addAttribute("userList",userList);

        return "productmodule/product-add";
    }

    @RequestMapping("/addProduct")
    public String add(Product product, HttpSession session, UploadUtil upload) throws IOException {

        productService.save(product);
        if (upload != null) {
            String imageName = product.getId()+".jpg";

            File file = new File(session.getServletContext().getRealPath("/images/product"),imageName);

            System.out.println(session.getServletContext().getRealPath("/images/product"));

            file.getParentFile().mkdirs();
            upload.getImage().transferTo(file);

            System.out.println("["+product.getId()+","+"images/product/"+imageName+"]");

            ProductVO vo = new ProductVO();
            vo.setId(product.getId());
            vo.setImageUrl("images/product/"+imageName);

            productService.setImageURL(vo);

            System.out.println(productService.get(product.getId()));
        }
        return "redirect:list";
    }

    @RequestMapping("/deleteProduct")
    public String del(@RequestParam(value = "id")int id,HttpSession session){
        productService.del(id);
        String imageName = id+".jpg";
        File file = new File(session.getServletContext().getRealPath("/images/product"),imageName);
        file.delete();
        return "redirect:list";
    }

    @RequestMapping("/editProduct")
    public String editUI(@RequestParam(value = "id")int id,Model model){
        //获得要修改商品的信息
        Product product = productService.get(id);
        model.addAttribute("product",product);
        System.out.println(product);

        List<Category> categoryList = categoryService.list();
        List<User> userList = userService.list();
        //通过商品id 返回所属分类
        Category categoryByid = productService.getCategoryByCid(id);
        model.addAttribute("crrentCategory",categoryByid);
        //通过id返回所属商家
        User userById = userService.getUserByPid(id);
        model.addAttribute("crrentUser",userById);

        model.addAttribute("categoryList",categoryList);
        model.addAttribute("userList",userList);

        return "productmodule/product-edit";
    }

    @RequestMapping("/updateProduct")
    public String update(Product product, HttpSession session, UploadUtil upload) throws IOException {
        productService.update(product);
        if(upload!=null){

            String imageName = product.getId()+".jpg";

            File file = new File(session.getServletContext().getRealPath("/images/product"),imageName);

            file.getParentFile().mkdirs();
            upload.getImage().transferTo(file);

            ProductVO vo = new ProductVO();
            vo.setId(product.getId());
            vo.setImageUrl("images/product/"+imageName);

            productService.setImageURL(vo);

        }

        return "redirect:list";
    }

}

写在最后

(代码由于太多贴不全,如果有问题或者需要所有源码,可以加博主V交流: Code2Life2)

posted @ 2022-07-24 16:20  武红明  阅读(440)  评论(0编辑  收藏  举报