关于solr数据转换成Object的一个小总结

        使solr把solr中查出的数据转换成我们需要的Object,在网上查了一些方法,感觉有些复杂,就想找一个简单的方法,我的解决方案是这样的

public String fingBySolr(HttpServletRequest req) throws Exception{
		SolrQuery query=new SolrQuery();
		query.set("q","goods:*");
		query.set("fl", "id gams gcPrice gDes gDiscount gewNum gLNum gms gName gNum gPhoto gyPrice");
		QueryResponse response=httpSolrClient.query(query);
		SolrDocumentList lists=response.getResults();
		String json = JSONArray.toJSONString(lists);
		List<Good> goods = JSONArray.parseArray(json, Good.class);
		req.setAttribute("goods",goods);
		httpSolrClient.commit();
		return "/findGood.jsp";
	}

                               

猜你喜欢

转载自blog.csdn.net/LiDouDou1994/article/details/81437800