ssm中直接返回某个页面或存东西

1.直接返回页面“item_list”

	@RequestMapping("")
	public String Test1(){
		return "item_list";
	}

或者:

	@RequestMapping("")
	public ModelAndView Test2(){
		ModelAndView mav=new ModelAndView();
		mav.setViewName("item_list");
		return mav;
	}

2.存东西

	@RequestMapping("AllList.do")
	public String Test4(Model model){
		List itemList=itemService.selectAll();
		model .addAttribute("itemList", itemList);
		return "item_list";
	}

或者:

	@RequestMapping("AllList.do")
	public ModelAndView Test3(){
		ModelAndView mav=new ModelAndView();
		ItemInfo item1=new ItemInfo(1,"李疆","111");
		ItemInfo item2=new ItemInfo(2,"李二","222");
		ItemInfo item3=new ItemInfo(3,"张三","333");
		ItemInfo item4=new ItemInfo(4,"李四","444");
		List itemList=new ArrayList();
		itemList.add(item1);
		itemList.add(item2);
		itemList.add(item3);
		itemList.add(item4);
		mav.addObject("itemList", itemList);
		mav.setViewName("item_list");
		return mav;
	}

 

你可能感兴趣的:(SSM)