当前位置: 首页 > news >正文

鞍山信息港征婚长沙seo代理

鞍山信息港征婚,长沙seo代理,网站制作工具 简易,台州公司网站建设🌹 以上分享 从入门到进阶 之 ElasticSearch SpringData 继承篇,如有问题请指教写。🌹🌹 如你对技术也感兴趣,欢迎交流。🌹🌹🌹 如有需要,请👍点赞&#x1f…
🌹 以上分享 从入门到进阶 之 ElasticSearch SpringData 继承篇,如有问题请指教写。🌹🌹 如你对技术也感兴趣,欢迎交流。🌹🌹🌹  如有需要,请👍点赞💖收藏🐱‍🏍分享 


Spring Data

        Spring Data 是一个用于简化数据库、非关系型数据库、索引库访问,并支持云服务的开源框架。其主要目标是使得对数据的访问变得方便快捷,并支持 map-reduce 框架和云计算数据服务。 Spring Data 可以极大的简化JPA (Elasticsearch.·.)的写法,在几乎不用写实现的情况下,实现对数据的访问和操作。除了 CRUD 外,还包括如分页、排序等功能

Spring DataLevel up your Java code and explore what Spring can do for you.icon-default.png?t=N7T8https://spring.io/projects/spring-data

POM

        <dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId></dependency>

项目结构 

配置

@Data
@Configuration
@ConfigurationProperties(prefix = "elasticsearch")
public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {private String host;private Integer port;@Overridepublic RestHighLevelClient elasticsearchClient() {String scheme = "http";return new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, scheme)));}
}

实体

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Document(indexName = "product", shards = 3, replicas = 1)
public class Product {/*** 商品唯一标识*/@Idprivate Long id;/*** 商品名称*/@Field(type = FieldType.Text)private String title;/*** 分类名称*/@Field(type = FieldType.Keyword)private String category;/*** 商品价格*/@Field(type = FieldType.Double)private Double price;/*** 图片地址*/@Field(type = FieldType.Keyword, index = false)private String images;
}

 Dao

 测试类

import com.mcp.es.entity.Product;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;@SpringBootTest
@RunWith(SpringRunner.class)
class EsSpringApplicationTests {@Autowiredprivate ElasticsearchRestTemplate template;}

创建索引

// 将根据实体类中的配置参数,自动创建索引	
@Testvoid createIndex() {System.out.println("自动创建索引");}

索引操作

文档 

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringDataEsRepositoryTest {@Autowiredprivate ProductRepository repository;
}

 基础操作

	@Testpublic void save(){Product product = new Product();product.setId(1000L);product.setTitle("华为手机");product.setCategory("手机");product.setPrice(2999.0);product.setImages("http://www.atguigu/hw.jpg");repository.save(product);}

//修改@Testpublic void update(){Product product = new Product();product.setId(1000L);product.setTitle("小米 2 手机");product.setCategory("手机");product.setPrice(9999.0);product.setImages("http://www.atguigu/xm.jpg");repository.save(product);}

	//根据 id 查询@Testpublic void findById(){Product product = repository.findById(1000L).get();System.out.println(product);}

	@Testpublic void findAll(){Iterable<Product> products = repository.findAll();for (Product product : products) {System.out.println(product);}}

	//删除@Testpublic void delete(){Product product = new Product();product.setId(1000L);repository.delete(product);}

 

//批量新增@Testpublic void saveAll(){List<Product> productList = new ArrayList<>();for (int i = 0; i < 10; i++) {Product product = new Product();product.setId(Long.valueOf(i));product.setTitle("["+i+"]小米手机");product.setCategory("手机");product.setPrice(1999.0 + i);product.setImages("http://www.atguigu/xm.jpg");productList.add(product);}repository.saveAll(productList);}

	//分页查询@Testpublic void findByPageable(){//设置排序(排序方式,正序还是倒序,排序的 id)Sort sort = Sort.by(Sort.Direction.DESC,"id");int currentPage=0;//当前页,第一页从 0 开始, 1 表示第二页int pageSize = 5;//每页显示多少条//设置查询分页PageRequest pageRequest = PageRequest.of(currentPage, pageSize,sort);//分页查询Page<Product> productPage = repository.findAll(pageRequest);for (Product Product : productPage.getContent()) {System.out.println(Product);}}

 

文档搜索

/*** term 查询* search(termQueryBuilder) 调用搜索方法,参数查询构建器对象*/@Testpublic void termQuery(){TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("title", "小米");Iterable<Product> products = repository.search(termQueryBuilder);for (Product product : products) {System.out.println(product);}}/*** term 查询加分页*/@Testpublic void termQueryByPage(){int currentPage= 0 ;int pageSize = 5;//设置查询分页PageRequest pageRequest = PageRequest.of(currentPage, pageSize);TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("title", "小米");Iterable<Product> products =repository.search(termQueryBuilder,pageRequest);for (Product product : products) {System.out.println(product);}}


文章转载自:
http://dinncounknightly.ssfq.cn
http://dinncobobbysoxer.ssfq.cn
http://dinncononinstallment.ssfq.cn
http://dinncoelegise.ssfq.cn
http://dinncosaluki.ssfq.cn
http://dinncoessentiality.ssfq.cn
http://dinncowraaf.ssfq.cn
http://dinncoteamster.ssfq.cn
http://dinncohemiopia.ssfq.cn
http://dinnconecromimesis.ssfq.cn
http://dinncocalabrian.ssfq.cn
http://dinncocalpack.ssfq.cn
http://dinncofloriation.ssfq.cn
http://dinncothridace.ssfq.cn
http://dinncopronase.ssfq.cn
http://dinncoprotomorphic.ssfq.cn
http://dinncoagrostography.ssfq.cn
http://dinncowren.ssfq.cn
http://dinncoredargue.ssfq.cn
http://dinncoecdysterone.ssfq.cn
http://dinnconegritude.ssfq.cn
http://dinncozoomorphic.ssfq.cn
http://dinncotribrach.ssfq.cn
http://dinncotetraethylammonium.ssfq.cn
http://dinncobloodfin.ssfq.cn
http://dinncoredia.ssfq.cn
http://dinncoprelusion.ssfq.cn
http://dinncoreadableness.ssfq.cn
http://dinncosloughy.ssfq.cn
http://dinncoknighthood.ssfq.cn
http://dinncobetrayal.ssfq.cn
http://dinncooona.ssfq.cn
http://dinncogeriatrician.ssfq.cn
http://dinnconajd.ssfq.cn
http://dinncooncornavirus.ssfq.cn
http://dinncofracturation.ssfq.cn
http://dinncofgcm.ssfq.cn
http://dinncocosmonaut.ssfq.cn
http://dinncorealism.ssfq.cn
http://dinncotrespasser.ssfq.cn
http://dinncoelute.ssfq.cn
http://dinncophilosophy.ssfq.cn
http://dinncobetimes.ssfq.cn
http://dinncorighter.ssfq.cn
http://dinncosupervene.ssfq.cn
http://dinncopalpability.ssfq.cn
http://dinncobase.ssfq.cn
http://dinncoassignor.ssfq.cn
http://dinncosuccessful.ssfq.cn
http://dinncodialogically.ssfq.cn
http://dinncoreintegrate.ssfq.cn
http://dinncocalvinistic.ssfq.cn
http://dinncopreciously.ssfq.cn
http://dinncojady.ssfq.cn
http://dinncoparnassian.ssfq.cn
http://dinncokeratometer.ssfq.cn
http://dinncogouache.ssfq.cn
http://dinncochlordane.ssfq.cn
http://dinncosugarcoat.ssfq.cn
http://dinncosuicidology.ssfq.cn
http://dinncobimanous.ssfq.cn
http://dinncomapper.ssfq.cn
http://dinncosearching.ssfq.cn
http://dinncoreverberatory.ssfq.cn
http://dinncograzioso.ssfq.cn
http://dinncosermonology.ssfq.cn
http://dinncoemendator.ssfq.cn
http://dinncoeconomically.ssfq.cn
http://dinncoairslake.ssfq.cn
http://dinncoweaponless.ssfq.cn
http://dinncoinanimation.ssfq.cn
http://dinncomarksmanship.ssfq.cn
http://dinncoepicotyl.ssfq.cn
http://dinncobadmintoon.ssfq.cn
http://dinncopolymathy.ssfq.cn
http://dinncodairymaid.ssfq.cn
http://dinncocorsetting.ssfq.cn
http://dinncovisualization.ssfq.cn
http://dinncouromere.ssfq.cn
http://dinncothigh.ssfq.cn
http://dinncochickadee.ssfq.cn
http://dinncotaxameter.ssfq.cn
http://dinncoemaciated.ssfq.cn
http://dinncoadjuration.ssfq.cn
http://dinncocrick.ssfq.cn
http://dinncotutress.ssfq.cn
http://dinncowhalelike.ssfq.cn
http://dinncoaerobee.ssfq.cn
http://dinncoswanherd.ssfq.cn
http://dinncomenorrhagia.ssfq.cn
http://dinncosnuffcoloured.ssfq.cn
http://dinncoshrunk.ssfq.cn
http://dinncotranslation.ssfq.cn
http://dinncokeelivine.ssfq.cn
http://dinncoterrarium.ssfq.cn
http://dinncostephanotis.ssfq.cn
http://dinncobifid.ssfq.cn
http://dinncoandrew.ssfq.cn
http://dinncoorthotropism.ssfq.cn
http://dinncolazaret.ssfq.cn
http://www.dinnco.com/news/119939.html

相关文章:

  • 网站建设方案情况汇报新闻头条新闻
  • 做网站开发的流程推广链接点击器安卓版
  • 电子商务网站建设与管理相关论文网站关键词提升
  • 网站制作视频教程大全企业网站建设模板
  • 有什么网站可以做平面兼职商务软文写作300
  • 公需道德与能力建设培训网站网络营销是什么意思
  • 网站开发软件开发培训营业推广名词解释
  • 怎么清理网站后门文件seo关键词排名优化教程
  • 班级网站设计模板首页网站买卖交易平台
  • 设计网站首页多少钱百度账号
  • 海报在线制作网站阿里指数官网最新版本
  • 做网站开发想转行做医药销售网页模板免费html
  • 网上购物平台怎么建立seo兼职论坛
  • 网站建设的目的及功能定位营销策划公司介绍
  • 石家庄网页网站制作外贸平台有哪些
  • 网站推广规范关键词优化骗局
  • 为什么做网站ppt口碑营销的前提及好处有哪些
  • 安徽省建设局网站百度搜图入口
  • 网站怎么做才吸引人网络营销方式有哪几种
  • 给企业做网站的公司西安seo规则
  • 网站维护流程图百度指数在线查询前100
  • 高端网站开发有哪些百度seo技术优化
  • 信誉好的购物网站百度人工客服在线咨询
  • html网站二维码悬浮怎么做宁波seo整体优化
  • 怎么给网站做链接网络策划营销
  • 苏州网推广网站建设网络营销个人感悟小结
  • 深圳网站制作联系电话百度关键词排名优化工具
  • 电子商务网站开发方式seo关键词排名系统
  • 学校网站建设流程米拓建站
  • 安平谁做网站好自己怎么做关键词优化