首页>代码>spring+spring mvc+mybatis+mysql+maven整合开发服装购物商城实例>/shop/src/main/java/com/zgzcwy/controller/HomeController.java
package com.zgzcwy.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

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 com.zgzcwy.entity.Category;
import com.zgzcwy.entity.Product;
import com.zgzcwy.service.CategoryService;
import com.zgzcwy.service.ProductService;

/**
 * @ClassName:  HomeController   
 * @Description:   进入网站主页的控制器
 * @author: Administrator  
 * @date:   2017年12月28日 下午4:25:15   
 *
 */
@Controller
public class HomeController{
	@Autowired 
	private CategoryService categoryService;
	@Autowired
	private ProductService productService;
	//热门商品的集合
	private List<Product> hotList;
	//最新商品集合
	private List<Product> newList;
	/**
	 * 首页访问的方法
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/index")
	public String index(HttpSession session,Model model) throws Exception{
		//1.查询所有一级分类
		List<Category> categoryList = categoryService.findAllCategory();
		//2.将查询出来的所有存入session
		session.setAttribute("categoryList", categoryList);
		//查询热门商品
		hotList=productService.findAllHotProduct();
		model.addAttribute("hotList", hotList);
		//查询最新商品
		newList=productService.findAllNewProduct();
		model.addAttribute("newList", newList);
		return "index";
	}
	/**
	 * 跳转到注册页面
	 * @return
	 */
	@RequestMapping("/userRegist")
	public String userRegist() throws Exception{
		return "regist";
	}
	/**
	 * 跳转到激活页面
	 */
	@RequestMapping("/message")
	public String message() throws Exception{
		return "msg";
	}
	/**
	 * 跳转到用户登录页面
	 */
	@RequestMapping("/loginPage")
	public String loginPage() throws Exception{
		return "login";
	}

}
最近下载更多
杨豫川  LV12 1月15日
微信网友_6680567232876544  LV8 2023年10月10日
gecongkai  LV8 2023年6月23日
teamdragon  LV6 2023年5月17日
微信网友_6436772032335872  LV3 2023年4月17日
601601lmy  LV5 2023年3月5日
22344341  LV2 2023年1月27日
LITIANYU084414  LV11 2023年1月4日
1349958941  LV3 2022年12月28日
微信网友_6258245891903488  LV7 2022年12月12日
最近浏览更多
万紫怡  LV4 3月8日
李朝磊  LV18 3月6日
wbw123  LV5 3月1日
xiaojie93  LV2 3月1日
lihao0217  LV1 2月15日
liiiyou  LV1 1月26日
ljhgff  LV1 1月18日
杨豫川  LV12 1月15日
qwe6002  LV9 1月12日
zcwmmd  LV20 1月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友