首页>代码>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";
    }
}
最近下载更多
小海脑洞大开  LV11 3月20日
wbw123  LV5 3月1日
李朝磊  LV18 2月2日
admin_z  LV22 2023年12月22日
rain112  LV30 2023年11月29日
微信网友_6658069491355648  LV2 2023年10月18日
hmdzmsl12  LV2 2023年7月17日
include  LV8 2023年6月20日
微信网友_6499449700175872  LV4 2023年5月31日
linshibo  LV5 2023年5月10日
最近浏览更多
860421  LV3 前天
shaojie xu 4月16日
暂无贡献等级
郁以泠 4月13日
暂无贡献等级
月之氏族  LV23 4月12日
玖零定制问题修复  LV34 4月4日
小海脑洞大开  LV11 3月20日
wbw123  LV5 3月1日
李朝磊  LV18 2月2日
qq_1234 1月24日
暂无贡献等级
zhos0212  LV19 1月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友