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

给蛋糕店做企业网站的文案培训机构网站模板

给蛋糕店做企业网站的文案,培训机构网站模板,有了域名和空间怎么做网站,邯郸市最新招聘信息简介 Spring Data for Elasticsearch 是 Spring Data 项目的一部分,该项目旨在为新数据存储提供熟悉且一致的基于 Spring 的编程模型,同时保留特定于存储的特性和功能。 Spring Data Elasticsearch 项目提供了与 Elasticsearch 搜索引擎的集成。Spring…

简介

Spring Data for Elasticsearch 是 Spring Data 项目的一部分,该项目旨在为新数据存储提供熟悉且一致的基于 Spring 的编程模型,同时保留特定于存储的特性和功能。

Spring Data Elasticsearch 项目提供了与 Elasticsearch 搜索引擎的集成。Spring Data Elasticsearch 的关键功能领域是以 POJO 为中心的模型,用于与 Elastichsearch 文档交互并轻松编写存储库样式的数据访问层。

简单使用

1.创建SpringBoot项目,导入Spring Data Elasticsearch的起步依赖。

/*elasticsearch的起步依赖*/ 
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>/*lomobok起步依赖*/<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional>
</dependency>

2.编写配置文件,连接ElasticSearch

spring:elasticsearch:uris: https://192.168.66.101:9200username: elasticpassword: 12345678

 打印日志 

logging: pattern: console: '%d{HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n'

ES8 开始,访问 ES 的协议从 http 变成了 https ,访问 https 请求 需要SSL 证书,在开发环境下我们不需要配置该证书,在项目中 添加一个配置类,跳过SSL 证书检查即可。

3.创建配置类跳过SSL证书检查 

@Component
public class RestClientBuilderCustomizerImpl implements RestClientBuilderCustomizer {@Overridepublic void customize(RestClientBuilder builder) {}/*** 跳过SSL的证书检查*/@Overridepublic void customize(HttpAsyncClientBuilder builder) {SSLContextBuilder sscb = SSLContexts.custom();try {sscb.loadTrustMaterial((chain, authType) -> {return true;});} catch (NoSuchAlgorithmException e) {throw new RuntimeException(e);} catch (KeyStoreException e) {throw new RuntimeException(e);}try {builder.setSSLContext(sscb.build());} catch (KeyManagementException | NoSuchAlgorithmException e) {e.printStackTrace();}}
}

 4.创建实体类

一个实体类的所有对象都会存入 ES 的一个索引中,所以我们在创建实体类时关联ES 索引
@Document(indexName = "product",createIndex = true)  //关联名为product的索引
@Data
@AllArgsConstructor
public class Product {@Id //标记在成员变量上,标记一个字段为主键,该字段的值会同步到ES该文档的id值//标记在成员变量上,标记为文档中的域,一般有如下属性->// type域的类型,index是否创建索引,store是否单独存储,analyzer分词器,searchAnalyzer搜索分词器@Field(type = FieldType.Integer,store = true,index = true)private Integer id;@Field(type = FieldType.Text,store = true,index = true,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")private String productName;@Field(type = FieldType.Text,store = true,index = true,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")private String productDesc;
}

 5.创建Repository接口

Repository 接口继承 ElasticsearchRepository, 该接口提供了文档的增删改查方法
@Repository
public interface ProductRepository extends ElasticsearchRepository<Product,Integer> {
}

6.测试Repository接口

6.1测试保存和修改方法

@SpringBootTest
public class ProductRepositoryTest {@Autowiredprivate ProductRepository repository;//保存文档public void addProduct(){Product product = new Product(1, "今天是第一天", "第一天plus");repository.save(product);}//修改方法(当该文档已经存在,即对其进行修改)public void addProduct(){Product product = new Product(1, "今天是第first天", "第first天plus");repository.save(product);}
}

6.2查找文档方法

6.2.1根据id进行查询
@Testpublic void findById(){Optional<Product> byId = repository.findById(1);System.out.println(byId.get());}
6.2.2查询所有文档
@Testpublic void findAll(){repository.findAll().forEach(System.out::println);}

6.3测试删除方法

//根据其主键id进行删除
@Testpublic void deleteById(){repository.deleteById(1);}

7.使用DSL语句查询文档

query 后的 json 对象称为 DSL语句 ,我们可以在接口方法上使用 @Query注解自定义 DSL 语句查询。

 在Repository接口层编写方法

7.1 匹配查询

@Repository
public interface ProductRepository extends ElasticsearchRepository<Product,Integer> {//匹配查询@Query("{\n" +"    \"match\": {\n" +"      \"productDesc\": \"?0\"\n" +"    }\n" +"  }")List<Product> findByProductDescMatch(String keyword);
}

7.2模糊查询

@Repository
public interface ProductRepository extends ElasticsearchRepository<Product,Integer> {@Query(" {\n" +"    \"match\": {\n" +"      \"productDesc\":{\n" +"        \"query\": \"\\?0\",\n" +"        \"fuzziness\": 1\n" +"      }\n" +"    }\n" +"  }")List<Product> findByProductDescFuzzy(String keyword);
}

8.按照规则命名方法查询文档

 1.只需在 Repository 接口中按照一定的规则命名方法,该方法就能完成相应的查询
2. 规则:查询方法以 findBy 开头,涉及查询条件时,条件的属性用条件关键字连接。

8.1单条件查询

@Repository
public interface ProductRepository extends ElasticsearchRepository<Product,Integer> {//根据规则进行查询-通过productNameList<Product> findByProductName(String productName);
}

测试:

@Testpublic void testFindByProductName(){List<Product> byProductName = repository.findByProductName("iphone");byProductName.forEach(System.out::println);}

8.2 多条件选择查询

@Repository
public interface ProductRepository extends ElasticsearchRepository<Product,Integer> {
//测试按照规则命名使用    Or 查询
List<Product> findByProductNameOrProductDesc(String productName,String productDesc);
}

测试:

@Testpublic void testFindByProductNameOrProductDesc(){repository.findByProductNameOrProductDesc("iphone","三体").forEach(System.out::println);}

8.3范围查询

@Repository
public interface ProductRepository extends ElasticsearchRepository<Product,Integer> {//测试使用命名规则进行  范围查询
List<Product> findByIdBetween(Integer start,Integer end);
}

测试:

@Testpublic void testFindByProductIdBetween(){repository.findByIdBetween(1,3).forEach(System.out::println);}

9.分页查询

在使用继承或自定义的方法时,在方法中添加 Pageable 类型的参 数,返回值为Page 类型即可进行分页查询。

9.1继承方法

@Testpublic void testFindPage(){//参数1:当前页,从0开始,参数2:每页显示多少条Pageable pageable = PageRequest.of(0,3);Page<Product> all = repository.findAll(pageable);System.out.println("总条数:"+all.getTotalElements());System.out.println("总页数:"+all.getTotalPages());System.out.println("数据:"+all.getContent());}

10.分页查询并排序

10.1继承方法

使用继承或自定义的方法时,在方法中添加 Sort 类型的参数即可进行结果排序。
 @Testpublic void testFindPage2(){//既分页,又排序Sort sort = Sort.by(Sort.Direction.DESC, "id");Pageable pageable = PageRequest.of(0,3,sort);Page<Product> all = repository.findByProductDescMatch("体",pageable);System.out.println("总条数:"+all.getTotalElements());System.out.println("总页数:"+all.getTotalPages());System.out.println("数据:"+all.getContent());}


文章转载自:
http://endocrine.c7513.cn
http://bewilder.c7513.cn
http://flyte.c7513.cn
http://derisory.c7513.cn
http://millesimal.c7513.cn
http://exhibitioner.c7513.cn
http://weave.c7513.cn
http://pullback.c7513.cn
http://oregonian.c7513.cn
http://gimlety.c7513.cn
http://domiciliate.c7513.cn
http://tightknit.c7513.cn
http://regulate.c7513.cn
http://gossypol.c7513.cn
http://pentane.c7513.cn
http://nucleoprotein.c7513.cn
http://peeper.c7513.cn
http://chamfer.c7513.cn
http://ardent.c7513.cn
http://multigraph.c7513.cn
http://member.c7513.cn
http://ergatocracy.c7513.cn
http://deflexibility.c7513.cn
http://turncock.c7513.cn
http://soil.c7513.cn
http://detonable.c7513.cn
http://komsomolsk.c7513.cn
http://homebrewed.c7513.cn
http://difunctional.c7513.cn
http://hephaestus.c7513.cn
http://inalterable.c7513.cn
http://digestible.c7513.cn
http://san.c7513.cn
http://apologetics.c7513.cn
http://bedash.c7513.cn
http://subadar.c7513.cn
http://dolabriform.c7513.cn
http://insolvable.c7513.cn
http://localise.c7513.cn
http://twisteroo.c7513.cn
http://stippling.c7513.cn
http://anaphoric.c7513.cn
http://electromotion.c7513.cn
http://retable.c7513.cn
http://goloptious.c7513.cn
http://hawkshaw.c7513.cn
http://staniel.c7513.cn
http://grey.c7513.cn
http://bulldyke.c7513.cn
http://kanoon.c7513.cn
http://nematicidal.c7513.cn
http://hoof.c7513.cn
http://garni.c7513.cn
http://turncock.c7513.cn
http://complaining.c7513.cn
http://uxoriously.c7513.cn
http://akee.c7513.cn
http://reawaken.c7513.cn
http://foresail.c7513.cn
http://rubasse.c7513.cn
http://fellness.c7513.cn
http://slumland.c7513.cn
http://plotter.c7513.cn
http://maritage.c7513.cn
http://cmos.c7513.cn
http://schizothyme.c7513.cn
http://cismontane.c7513.cn
http://leveler.c7513.cn
http://intrauterine.c7513.cn
http://beirut.c7513.cn
http://leukopoiesis.c7513.cn
http://stab.c7513.cn
http://railman.c7513.cn
http://behave.c7513.cn
http://effort.c7513.cn
http://specilization.c7513.cn
http://knob.c7513.cn
http://spittlebug.c7513.cn
http://trinitrophenol.c7513.cn
http://bagpiper.c7513.cn
http://fearful.c7513.cn
http://santana.c7513.cn
http://redan.c7513.cn
http://improver.c7513.cn
http://senora.c7513.cn
http://bodiless.c7513.cn
http://pustular.c7513.cn
http://splintery.c7513.cn
http://copacetic.c7513.cn
http://porno.c7513.cn
http://periodize.c7513.cn
http://wheeled.c7513.cn
http://innovation.c7513.cn
http://sasswood.c7513.cn
http://underbid.c7513.cn
http://crankpin.c7513.cn
http://cubical.c7513.cn
http://bleep.c7513.cn
http://ametropia.c7513.cn
http://calorigenic.c7513.cn
http://www.zhongyajixie.com/news/94269.html

相关文章:

  • 中国做爰网站长春网站优化哪家好
  • b站视频怎么引用到wordpress下店拓客团队
  • 梅兰商贸网站开发设计简介国外搜索引擎有哪些
  • godaddy 搭建网站百度号码认证平台首页
  • 警告 此服务器美国维护360seo优化
  • 潍坊网站建设尚荣公司宣传网页怎么做
  • 微信商城和微网站建设口碑营销案例分析
  • 自己做店招的网站免费建网站的平台
  • 建设网站视频教程整合网络营销公司
  • 山东省建设厅网站一体化平台互联网项目推广是什么
  • 网站后台管理怎么做网络营销推广策划
  • 深圳城市规划设计研究官方网站独立网站怎么做
  • 网站建设怎么寻找客户seo网页优化培训
  • 学做ps的软件的网站百度竞价一个月5000够吗
  • 网络推广心得体会seo研究中心道一老师
  • wordpress html5播放器重庆seo整站优化效果
  • 网页制作与网站建设项目教程乐陵市seo关键词优化
  • 做设计什么兼职网站建设网络营销软件推广
  • 抚州做网站价格多少销售管理
  • 团购网站制作2022智慧树互联网与营销创新
  • 滨州哪里有做网站的网站营销
  • 信息网站的建设产品seo怎么优化
  • 网站建设一般字体多大百度问一问付费咨询
  • 如何用电脑主机做网站网络快速排名优化方法
  • 湖北建设厅造价网站来几个关键词兄弟们
  • 给网站整一个客服 怎么做百度收录推广
  • 专门做游戏攻略的网站站长工具流量统计
  • 网站一键制作来客seo
  • 网站做后台seo推广灰色词
  • 深圳微网站建设百度关键词优化怎么做