侧边栏壁纸
  • 累计撰写 781 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

与modelAndView交互

Dettan
2021-04-10 / 0 评论 / 0 点赞 / 103 阅读 / 1,017 字
温馨提示:
本文最后更新于 2022-04-30,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
定义并传入数据
@RequestMapping("homeIndex")
public ModelAndView homeIndex(HttpServletRequest request,HttpServletResponse response){
	ModelAndView mav = new ModelAndView();
	response.setContentType("text/html;charset=utf-8");
	List<Tourist> list = new ArrayList<Tourist>();
	list=this.touristService.findTouristList(new Tourist());
	List<ZiXuninfo> zxs = new ArrayList<ZiXuninfo>();
	zxs = this.ziXuninfoService.findZiXunList(new ZiXuninfo());
	User user = (User)request.getSession().getAttribute("user");
	List<Hotel> hotels=this.hotelService.findHotelList(new Hotel());
	List<TouristTrace> traces = this.touristTaceService.findTouristTraceList( new TouristTrace());
	mav.addObject("zxs", zxs);
	mav.setViewName("site/index");
	mav.addObject("tourist",list);
	mav.addObject("user",user);
	mav.addObject("hotels", hotels);
	mav.addObject("traces", traces);
	System.out.println(mav);
	return mav;
}
获取数据
request.getAttribute("tourist");

0

评论区