SpringMVC传递数据前台无法接收

	@Autowired
	private ElasticsearchTemplate esTemplate;	

        @RequestMapping(value="/search",method=RequestMethod.GET)
	public ModelAndView  search(Model model) {
		ModelAndView mav = new ModelAndView();
		List list = new ArrayList();
		list.add("123456");
		List users =new ArrayList();
		SearchQuery searchQuery =new               NativeSearchQueryBuilder().withIds(list).build();
		users = esTemplate.queryForList(searchQuery, User.class);
		System.out.println(users);
		mav.addObject(users);
		mav.setViewName("es");	
		return mav;
	}

 

  前台用Jsp页面进行接收

    
        nickName
OpenId
sex
province
city
country

使用SpringMVC 从es获取数据后,传递到前台发现前台无法获取到数据。后来检查了半天,在朋友的帮助下

 将代码

mav.addObject(users);

改为:

mav.addObject("users", users);

结果就可以获取到数据了,有人知道为什么吗?感激不尽!

你可能感兴趣的:(错误)