添加solr库工具类


/**
* 通过该类一次性导入数据库的Tbitem所有数据到solr库
*/
@Component
public class SolrUtil {

@Autowired
private TbItemMapper itemMapper;

@Autowired
private SolrTemplate solrTemplate;

public void importDate(){
//查询出所有tbitem数据
List<TbItem> items = itemMapper.selectByExample(null);

System.out.println("导入了:"+items.size());

solrTemplate.saveBeans(items); //直接将集合保存到solr库

solrTemplate.commit();
}

public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath*:spring/applicationContext*.xml");
SolrUtil util = (SolrUtil) ac.getBean("solrUtil");
util.importDate();
}
}

原文地址:https://www.cnblogs.com/otways/p/10219437.html