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

旅游景点网站模板大全阳东网站seo

旅游景点网站模板大全,阳东网站seo,备案网站打不开,易县做网站的在哪传送门: MongoDB文档--基本概念_一单成的博客-CSDN博客 MongoDB文档--基本安装-linux安装(mongodb环境搭建)-docker安装(挂载数据卷)-以及详细版本对比_一单成的博客-CSDN博客 MongoDB文档--基本安装-linux安装&…

  传送门:

MongoDB文档--基本概念_一单成的博客-CSDN博客

MongoDB文档--基本安装-linux安装(mongodb环境搭建)-docker安装(挂载数据卷)-以及详细版本对比_一单成的博客-CSDN博客

MongoDB文档--基本安装-linux安装(mongodb环境搭建)-docker安装(挂载数据卷)-以及详细版本对比_一单成的博客-CSDN博客

MongoDB文档-基础使用-在客户端(dos窗口)/可视化工具中使用MongoDB基础语句_一单成的博客-CSDN博客

MongoDB文档-进阶使用-MongoDB索引-createindex()与dropindex()-在MongoDB中使用正则表达式来查找_一单成的博客-CSDN博客

使用技术介绍:
        概念说明:

        spring-data-mongodb 提供 MongoTemplate 与 MongoRepository两种操作方式
MongoRepository 操作简单 缺点是不够灵活
MongoTemplate 操作灵活,在项目中可以灵活使用这两种方式

MongoTemplate 
        MongoTemplate是Spring Data MongoDB项目的一部分,它是一个Spring的扩展,为使用MongoDB数据库的应用程序提供了抽象层。MongoTemplate提供了一个简单而强大的方法来执行各种数据库操作,而无需编写低级别的MongoDB驱动程序代码。

MongoTemplate的主要功能包括:

插入和更新文档:MongoTemplate提供了一种方便的方法来插入和更新MongoDB数据库中的文档。
查询文档:MongoTemplate提供了多种查询方法,可以使用各种查询参数来检索数据库中的文档,包括查询条件、排序、限制和投影。
聚合操作:MongoTemplate支持聚合框架,可以执行复杂的聚合操作,如计数、分组、求和等。
索引管理:MongoTemplate可以创建、删除和查询数据库索引。
命令和操作:MongoTemplate还支持各种数据库命令和操作,如计算数据库统计信息、执行存储过程等。
使用MongoTemplate可以简化MongoDB数据库操作的开发工作,提供更高的生产力和更好的可维护性。

MongoRepository
MongoRepository是Spring Data MongoDB项目中的另一个抽象层,它是基于MongoTemplate的更高级别的抽象。MongoRepository提供了一个基于注解的接口,用于定义与MongoDB数据库的交互。通过使用MongoRepository,你可以专注于定义数据访问逻辑,而无需编写低级别的数据库操作代码。

MongoRepository的主要功能包括:

查询文档:MongoRepository提供了一种方便的方法来查询数据库中的文档。通过使用注解,你可以定义查询条件、排序、限制和投影。
聚合操作:MongoRepository支持聚合框架,可以执行复杂的聚合操作,如计数、分组、求和等。
分页查询:MongoRepository提供了分页查询功能,可以限制查询结果的数量并获取下一页的结果。
自定义查询:如果你需要执行更复杂的查询操作,MongoRepository还提供了自定义查询的方法,可以编写存储过程或使用MongoDB的查询语言执行自定义查询。
使用MongoRepository可以使你的代码更加简洁和可维护,因为它提供了一种声明式的方式来访问MongoDB数据库。通过注解和自动实现的接口,你可以专注于实现业务逻辑,而无需关心底层的数据库操作细节。
 

使用MongoTemplate完成简单增删改查
常用方法

mongoTemplate.findAll(User.class): 查询User文档的全部数据

mongoTemplate.findById(<id>, User.class): 查询User文档id为id的数据

mongoTemplate.find(query, User.class);: 根据query内的查询条件查询

mongoTemplate.upsert(query, update, User.class): 修改

mongoTemplate.remove(query, User.class): 删除

mongoTemplate.insert(User): 新增

Query对象

1、创建一个query对象(用来封装所有条件对象),再创建一个criteria对象(用来构建条件)

2、 精准条件:criteria.and(“key”).is(“条件”)

模糊条件:criteria.and(“key”).regex(“条件”)

3、封装条件:query.addCriteria(criteria)

4、大于(创建新的criteria):Criteria gt = Criteria.where(“key”).gt(“条件”)

小于(创建新的criteria):Criteria lt = Criteria.where(“key”).lt(“条件”)

5、Query.addCriteria(new Criteria().andOperator(gt,lt));

6、一个query中只能有一个andOperator()。其参数也可以是Criteria数组。

7、排序 :query.with(new Sort(Sort.Direction.ASC, "age"). and(new Sort(Sort.Direction.DESC, "date")))
 

阿丹:

        使用MongoDB中的MongoTemplate来完成的好处就是可以自己构造Query所以在操作的时候更加的灵活!在加上底层的一些封装。更加的易读易学。

1、引入依赖

使用MongoDB的专属依赖

 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</artifactId></dependency>

        这个依赖是Spring Boot提供的用于与MongoDB数据库进行交互的starter依赖。它包含了所需的库和依赖项,以便在使用Spring Boot开发应用程序时方便地使用MongoDB。

具体来说,这个依赖提供了以下功能:

自动配置:Spring Boot会自动配置与MongoDB数据库的连接,包括创建Mongo客户端、设置连接属性等。
MongoTemplate:自动配置了MongoTemplate,这是一个用于执行各种数据库操作的核心类。通过使用MongoTemplate,你可以方便地进行文档的插入、更新、查询等操作。
MongoRepository:自动配置了MongoRepository,这是一个基于注解的接口,用于定义与MongoDB数据库的交互。通过继承MongoRepository,你可以方便地进行查询、聚合操作等。
模板化操作:通过使用MongoTemplate和MongoRepository,你可以以模板化的方式执行数据库操作,这使得代码更加简洁、可读性更好。
总之,通过添加这个依赖,可以方便地使用Spring Boot与MongoDB进行集成,而无需手动配置和编写低级别的数据库操作代码。

其他依赖:(如果小伙伴想直接开启一个简单的spring-boot项目可直接拿走)

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><scope>provided</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency></dependencies>

2、书写配置文件建立连接

书写applicaton.yml文件

spring:data:mongodb:host: 127.0.0.1 #指定MongoDB服务地址port: 27017 #指定端口,默认就为27017database: article#指定使用的数据库(集合)authentication-database: admin # 登录认证的逻辑库名username:  #用户名password:  #密码

注意:

        如果没有设置连接的用户的话可以根据实际情况删除一部分配置文件。

        相对于MySQL不一样的是:在MySQL中一个用户可以管理多个数据库,但是MongoDB每个库都要一个独立的管理用户,连接的时候需要输入对应的用户密码。

 3、实体类展示

主要注解:

         1、@Document,对应MongoDB中的文档,也就是数据库中的最基本的数据单元,由键值对组成,类似于JSON格式,可以存储不同字段,字段的值可以包括其他文档,数组和文档数组。

        2、@Id(主键):用来将成员变量的值映射为文档的_id的值,可以看我之前的文档有讲到如何给_id赋值。

        3、@Index(索引):索引是一种特殊的数据结构,存储在一个易于遍历读取的数据集合中,能够对数据文档中的数据进行排序。索引可以大大提高文档查询效率。

        4、@Field(字段):文档中的字段,类似于MySQL中的列概念。

        5、@Aggregation(聚合):聚合主要用于数据处理,例如统计平均值、求和等。
展示:

package com.example.mongodb_learn2.common;import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;/*** 阿丹实体类* */
@Data
@Document(collection = "ExampleDB")
public class Adn {@Id@Field("_id")private Long id;//阿丹主键@Field("name")private String name;//阿丹名称@Field("gender")private String gender;//阿丹性别@Field("specialty")private String specialty;//特长描述
}

注意:

        一定要去写@Field("name")这个注解,映射到字段的名字,不然查到的都是空!!!

4、上代码!正删改查开始!

controller控制层

package com.example.mongodb_learn2.controller;import com.example.mongodb_learn2.common.Adn;
import com.example.mongodb_learn2.service.AdnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;@RestController
public class AdnController {@Autowiredprivate AdnService adnService;/*** 根据id进行查找* */@GetMapping("/adnByid/{id}")public Adn getAdn(@PathVariable String id) {return adnService.getAdn(id);}/***添加阿丹* */@PostMapping("/saveAdn")public String saveAdn(@RequestBody Adn adn) {return adnService.saveAdn(adn);}/***根据id删除*/@GetMapping("/deleteAdn/{id}")public String deleteAdn(@PathVariable String id) {return adnService.deleteAdn(id);}/*** 修改* */@PostMapping("/updateAdn")public String updateAdn(@RequestBody Adn adn) {return adnService.updateAdn(adn);}/*** 查找所有展示列表* */@GetMapping("/getAllAdn")public List<Adn> getAllAdn() {return adnService.getAllAdn();}}

service层接口

package com.example.mongodb_learn2.service;import com.example.mongodb_learn2.common.Adn;import java.util.List;public interface AdnService {Adn getAdn(String id);String saveAdn(Adn adn);String deleteAdn(String id);String updateAdn(Adn adn);List<Adn> getAllAdn();
}

service层实现类

package com.example.mongodb_learn2.service.Impl;import com.alibaba.fastjson.JSON;
import com.example.mongodb_learn2.common.Adn;
import com.example.mongodb_learn2.service.AdnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class AdnServiceImpl implements AdnService {@Autowiredprivate MongoTemplate mongoTemplate;@Overridepublic Adn getAdn(String id) {return mongoTemplate.findById(id, Adn.class);}@Overridepublic String saveAdn(Adn adn) {Adn save = mongoTemplate.save(adn);return JSON.toJSONString(save);}@Overridepublic String deleteAdn(String id) {Query query = new Query();query.addCriteria(Criteria.where("id").is(id));mongoTemplate.remove(query, Adn.class);return id;}@Overridepublic String updateAdn(Adn adn) {Query query = new Query();query.addCriteria(Criteria.where("id").is(adn.getId()));Update update = new Update();update.set("name", adn.getName());update.set("gender", adn.getGender());update.set("specialty", adn.getSpecialty());mongoTemplate.updateFirst(query,update,Adn.class);Long id = adn.getId();return id+"";}@Overridepublic List<Adn> getAllAdn() {return mongoTemplate.findAll(Adn.class);}
}

可以看到使用MongoTemplate的优势就是更加的灵活。可以自定义化。


文章转载自:
http://dinncoimmunoelectrophoresis.ydfr.cn
http://dinncostalker.ydfr.cn
http://dinncotechnic.ydfr.cn
http://dinncotanta.ydfr.cn
http://dinncoregina.ydfr.cn
http://dinncoreloader.ydfr.cn
http://dinncoentailment.ydfr.cn
http://dinncolieder.ydfr.cn
http://dinncofloriation.ydfr.cn
http://dinncoadvertize.ydfr.cn
http://dinncoramus.ydfr.cn
http://dinncofreehearted.ydfr.cn
http://dinncosagamore.ydfr.cn
http://dinncogallantry.ydfr.cn
http://dinncorummer.ydfr.cn
http://dinncocubage.ydfr.cn
http://dinncorateen.ydfr.cn
http://dinncobarefooted.ydfr.cn
http://dinncophantasmagoric.ydfr.cn
http://dinncoelysee.ydfr.cn
http://dinncoglacialist.ydfr.cn
http://dinncochonju.ydfr.cn
http://dinncospectrochemistry.ydfr.cn
http://dinncoacapriccio.ydfr.cn
http://dinncoescorial.ydfr.cn
http://dinncotibial.ydfr.cn
http://dinncosubrogation.ydfr.cn
http://dinncounkennel.ydfr.cn
http://dinncovitrum.ydfr.cn
http://dinncotransvaluation.ydfr.cn
http://dinncoclv.ydfr.cn
http://dinncohyphenated.ydfr.cn
http://dinncoaraucan.ydfr.cn
http://dinncoroburite.ydfr.cn
http://dinncohammering.ydfr.cn
http://dinncobring.ydfr.cn
http://dinncofastigium.ydfr.cn
http://dinncobetimes.ydfr.cn
http://dinncodoctoral.ydfr.cn
http://dinncopuny.ydfr.cn
http://dinncogeopolitist.ydfr.cn
http://dinncophotoreactivation.ydfr.cn
http://dinncosyenitic.ydfr.cn
http://dinncorockabilly.ydfr.cn
http://dinncoeffeminacy.ydfr.cn
http://dinncomycenaean.ydfr.cn
http://dinncoperemptoriness.ydfr.cn
http://dinncograined.ydfr.cn
http://dinncopedagogism.ydfr.cn
http://dinncocockney.ydfr.cn
http://dinncoarghan.ydfr.cn
http://dinncoenzyme.ydfr.cn
http://dinncoperpent.ydfr.cn
http://dinncoidealistic.ydfr.cn
http://dinncosmattery.ydfr.cn
http://dinncorubbing.ydfr.cn
http://dinnconeanderthalian.ydfr.cn
http://dinncochamperty.ydfr.cn
http://dinncodisafforestation.ydfr.cn
http://dinncobowyer.ydfr.cn
http://dinncoglooming.ydfr.cn
http://dinncoshank.ydfr.cn
http://dinncogrunter.ydfr.cn
http://dinncobusman.ydfr.cn
http://dinncobillhead.ydfr.cn
http://dinncoabacterial.ydfr.cn
http://dinncovandyke.ydfr.cn
http://dinncotragedienne.ydfr.cn
http://dinncogrowing.ydfr.cn
http://dinncoforecabin.ydfr.cn
http://dinncoalunite.ydfr.cn
http://dinncozuni.ydfr.cn
http://dinncoepicedium.ydfr.cn
http://dinncosalvable.ydfr.cn
http://dinncoorwellism.ydfr.cn
http://dinncocrystallose.ydfr.cn
http://dinncoazonal.ydfr.cn
http://dinncoflavoprotein.ydfr.cn
http://dinncocanker.ydfr.cn
http://dinncovaleta.ydfr.cn
http://dinncozythum.ydfr.cn
http://dinncoenrich.ydfr.cn
http://dinncoenslaver.ydfr.cn
http://dinncothanatophobia.ydfr.cn
http://dinncoantiunion.ydfr.cn
http://dinncobromism.ydfr.cn
http://dinncoberet.ydfr.cn
http://dinncomisjoinder.ydfr.cn
http://dinncounpolled.ydfr.cn
http://dinncoanorak.ydfr.cn
http://dinncowia.ydfr.cn
http://dinncoultraminiaturize.ydfr.cn
http://dinncohypocenter.ydfr.cn
http://dinncoaccretion.ydfr.cn
http://dinncopleb.ydfr.cn
http://dinncoevulsion.ydfr.cn
http://dinncogramineous.ydfr.cn
http://dinncorespectful.ydfr.cn
http://dinncobehave.ydfr.cn
http://dinncopriapitis.ydfr.cn
http://www.dinnco.com/news/118178.html

相关文章:

  • 深圳南山网站建设昆山网站制作公司
  • 谷歌广告代理商aso优化方案
  • 做网店的网站外链生成工具
  • 什么网站可以做网站游戏推广员每天做什么
  • 怎么在网站做谷歌广告怎么推广平台
  • 校园门户网站系统建设关键技术seo网站搭建是什么
  • 做免费网站教程重庆网络推广外包
  • 自己的网站怎么做隐藏内容百度推广优化是什么意思
  • 最好的做网站的公司厦门谷歌seo公司有哪些
  • 改变网站的域名空间产品推广方式
  • 在哪个网站做视频可以赚钱图片识别搜索引擎
  • 公司 宜宾网站建设互联网推广方式有哪些
  • 网站备案时网站没有内容可以seo培训课程
  • 网站建设有哪些需求wordpress官网入口
  • 泉州建网站武汉seo首页优化报价
  • 企业网站的一般要素有整站优化seo公司哪家好
  • 张家界市建设局网站上海互联网公司排名
  • 网站设计高端邀请注册推广赚钱
  • 有哪些网站是做分期付款的网页制作培训教程
  • 劳务派遣做网站的好处打广告去哪个平台免费
  • 广州网站设计制作报价免费网页模板网站
  • 教学设计代做去什么网站可以免费网络推广网站
  • 网站知识架构抖音seo优化排名
  • 传奇网站怎么做百度怎么打广告
  • 石家庄58同城最新招聘信息长沙靠谱关键词优化服务
  • 计算机培训机构靠谱么天津站内关键词优化
  • vr模式的网站建设公司新东方留学机构官网
  • 企业网站为什么做优化营销推广外包公司
  • 天津建设工程信息网b1新北路站龙岗网站建设
  • wordpress建站工具包成人电脑培训班办公软件