首页>代码>springboot实现简单点餐系统>/diancan/src/main/java/com/ms/diancan/controller/api/HomeController.java
package com.ms.diancan.controller.api;

import com.ms.diancan.entity.*;
import com.ms.diancan.service.EvaService;
import com.ms.diancan.service.LeaveService;
import com.ms.diancan.service.NoticeService;
import com.ms.diancan.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author ms_miao
 * @createTime 2020-03-17 14:03
 */

@Controller
public class HomeController {
    @Autowired
    private NoticeService noticeService;
    @Autowired
    private ProductService productService;

    @Autowired
    private LeaveService leaveService;
    @Autowired
    private EvaService evaService;

    /**
  * 跳转到首页
     * @param model
     * @return
     */
    @GetMapping(value = {"/","/index"})
    public String home(Model model) {
        //1-获取上架商品信息
        List<Product> productList = productService.findAllProductList()
                .stream().filter(product -> product.getStatus() == 1).collect(Collectors.toList());
        //2-获取有效的公告信息
        List<Notice> validNoticeList = noticeService.findAll()
                .stream().filter(notice -> notice.getStatus() == 1).collect(Collectors.toList());
        //3-获取热门商品信息
        List<Product> hotProductList = new ArrayList<>();
        productService.findProductBannerByCount(3).forEach(productBanner ->{
            Product dbProduct = productService.findProductById(productBanner.getProductId());
            if(dbProduct != null) { hotProductList.add(dbProduct);}
        });
        //4-查询两条评论
        List<Evaluate> evaluateList = evaService.find2Eva();
        //5-所有的商品种类名
        List productKindList = productService.findAllProductKindNameList();
        //6-用户留言表
        List<Leave> leaveList = leaveService.findAllLeaveList();


        model.addAttribute("productList",productList);
        model.addAttribute("noticeList",validNoticeList);
        model.addAttribute("hotProductList",hotProductList.stream().limit(3).collect(Collectors.toList()));
        model.addAttribute("evaluateList",evaluateList);
        model.addAttribute("productKindList",productKindList);
        model.addAttribute("leaveList",leaveList);
        return "/pages/index";
    }
}
最近下载更多
krispeng  LV14 2024年12月30日
zolscy  LV24 2024年11月28日
y1214435276  LV9 2024年9月26日
TY0165  LV20 2024年6月19日
EEEEEEE19  LV1 2024年4月27日
小海脑洞大开  LV11 2024年3月20日
wbw123  LV5 2024年3月1日
李朝磊  LV18 2024年2月2日
admin_z  LV22 2023年12月22日
rain112  LV31 2023年11月29日
最近浏览更多
SX520886  LV6 4月24日
委屈99 3月2日
暂无贡献等级
陈小灏  LV18 2月25日
zyfile  LV1 1月9日
iiqe2024 2024年12月10日
暂无贡献等级
暂无贡献等级
yimaoermao  LV1 2024年11月28日
Daima000  LV4 2024年11月22日
xianyu091012  LV5 2024年11月18日
栾庆浩 2024年10月29日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友