Course handout of Java product purchase

Keywords: solr Spring xml Junit

Getting started with spring datasolr
1.1 introduction to spring data Solr
While the ability to support any programming language has great market value, the question you may be interested in is: how can I
Is Solr's application integrated into Spring? Yes, Spring Data Solr is a framework developed to facilitate the development of Solr. The bottom layer is the encapsulation of SolrJ (official API).

1.2 Spring Data Solr getting started Demo1.2.1 building project
(1) Create maven project and introduce dependency in pom.xml

















(2) Create applicationContext-solr.xml under src/main/resources

<?xml  version="1.0"  encoding="UTF-8"?>
<beans  xmlns="" xmlns:xsi=""
xmlns:p="" xmlns:context="" xmlns:solr="" xsi:schemaLocation="
[url=] ... spring-solr-1.0.xsd[/url]
[url=][/url] [url=][/url] [url=][/url] [url=][/url]">
<!--  solr server address -->

<solr:solr-server  id="solrServer"  url=""  />

<!--  solr Templates, using solr Templates can be used to CRUD Operation -->

<bean  id="solrTemplate"  class="">

<constructor-arg  ref="solrServer"  />



1.1.1 @Field annotation
Create cn.itcast.pojo package, copy the entity class of TbItem purchased by pinyougou into the project, and use @ Field annotation for attribute identification. If the property does not match the domain name defined in the configuration file, you need to specify the domain name in the annotation.

public  class  TbItem  implements  Serializable{


private  Long  id;


private  String  title;

private  BigDecimal  price;


private  String  image;


private  Long  goodsId;


private  String  category;


private  String  brand;


private  String  seller;



1.1.1 add (modify)
Create test class


public  class  TestTemplate  {


private  SolrTemplate  solrTemplate;


public  void  testAdd(){

TbItem  item=new  TbItem(); item.setId(1L);

item.setCategory("Mobile phone"); item.setGoodsId(1L);
item.setSeller("Huawei No.2 store");

item.setTitle("HUAWEI Mate9");

item.setPrice(new  BigDecimal(2000)); solrTemplate.saveBean(item); solrTemplate.commit();


Posted by fwegan on Thu, 02 Jan 2020 03:05:29 -0800