查詢索引庫數據之以JavaBean形式返回查...

@Test
    public void queryBeanTest() throws SolrServerException, IOException {
        // 連接solr服務器
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");

        // 創建查詢條件對象
        SolrQuery params = new SolrQuery("*:*");
        // 執行查詢,獲取響應數據
        QueryResponse response = solrServer.query(params);
        // 獲取結果集數據
        List<Item> list = response.getBeans(Item.class);
        // 處理結果集
        System.out.println("一共獲取了" + list.size()+"條結果:");
        for (Item item : list) {
            System.out.println("id: " + item.getId());
            System.out.println("title:" + item.getTitle());
        }
    }

查詢索引庫數據之以JavaBean形式返回查...

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章