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

旅游景点网站模板大全百度推广怎么做免费

旅游景点网站模板大全,百度推广怎么做免费,网站制作和收费标准,住建部四库一平台传送门: 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://dinncoretranslate.ssfq.cn
http://dinncodewbow.ssfq.cn
http://dinncodhurna.ssfq.cn
http://dinncoconservation.ssfq.cn
http://dinncotrucial.ssfq.cn
http://dinncoslithery.ssfq.cn
http://dinncolayard.ssfq.cn
http://dinncoimaginable.ssfq.cn
http://dinncocrepehanger.ssfq.cn
http://dinncoskippingly.ssfq.cn
http://dinncoscalene.ssfq.cn
http://dinncobuskin.ssfq.cn
http://dinncobalkh.ssfq.cn
http://dinncouncut.ssfq.cn
http://dinncohistoried.ssfq.cn
http://dinncograte.ssfq.cn
http://dinncoextol.ssfq.cn
http://dinncoaciform.ssfq.cn
http://dinncomewl.ssfq.cn
http://dinncoperpetrator.ssfq.cn
http://dinncoinfundibulum.ssfq.cn
http://dinncobulawayo.ssfq.cn
http://dinncoantithyroid.ssfq.cn
http://dinncohydridic.ssfq.cn
http://dinncopaprika.ssfq.cn
http://dinncophilogynist.ssfq.cn
http://dinncopinaster.ssfq.cn
http://dinncoconfab.ssfq.cn
http://dinncofusel.ssfq.cn
http://dinncokvar.ssfq.cn
http://dinncounscanned.ssfq.cn
http://dinncoas.ssfq.cn
http://dinncomelancholic.ssfq.cn
http://dinncofigueras.ssfq.cn
http://dinncostockinet.ssfq.cn
http://dinncomidweek.ssfq.cn
http://dinncohypohypophysism.ssfq.cn
http://dinncolender.ssfq.cn
http://dinncogrosbeak.ssfq.cn
http://dinncohabitus.ssfq.cn
http://dinncomanfully.ssfq.cn
http://dinncoexecrable.ssfq.cn
http://dinncoembryulcia.ssfq.cn
http://dinncocontainership.ssfq.cn
http://dinncomyoatrophy.ssfq.cn
http://dinncoposnet.ssfq.cn
http://dinncomalthusianism.ssfq.cn
http://dinncoinappetence.ssfq.cn
http://dinncochieftaincy.ssfq.cn
http://dinncothundery.ssfq.cn
http://dinncorill.ssfq.cn
http://dinncowittgensteinian.ssfq.cn
http://dinncopreemergent.ssfq.cn
http://dinncorashness.ssfq.cn
http://dinncocripes.ssfq.cn
http://dinncotabet.ssfq.cn
http://dinncohydratable.ssfq.cn
http://dinncoresurgent.ssfq.cn
http://dinncoundermentioned.ssfq.cn
http://dinncopraseodymium.ssfq.cn
http://dinncosalvy.ssfq.cn
http://dinncocholine.ssfq.cn
http://dinncopuffer.ssfq.cn
http://dinncoparticipance.ssfq.cn
http://dinncoxmas.ssfq.cn
http://dinncohorsey.ssfq.cn
http://dinncoseajelly.ssfq.cn
http://dinncodetrimentally.ssfq.cn
http://dinncobuhrstone.ssfq.cn
http://dinncoisoneph.ssfq.cn
http://dinncolangoustine.ssfq.cn
http://dinncoheadstream.ssfq.cn
http://dinncotetravalent.ssfq.cn
http://dinncofhwa.ssfq.cn
http://dinncooutcross.ssfq.cn
http://dinncoelectrorefining.ssfq.cn
http://dinncoinsuppressible.ssfq.cn
http://dinncoexultingly.ssfq.cn
http://dinncomacabre.ssfq.cn
http://dinncomanservant.ssfq.cn
http://dinncostaggering.ssfq.cn
http://dinncodiscountable.ssfq.cn
http://dinncocouncilwoman.ssfq.cn
http://dinncotethyan.ssfq.cn
http://dinncodownless.ssfq.cn
http://dinncorapc.ssfq.cn
http://dinncoichthyolatry.ssfq.cn
http://dinncosolmizate.ssfq.cn
http://dinncofissile.ssfq.cn
http://dinncocranioscopy.ssfq.cn
http://dinncokimbundu.ssfq.cn
http://dinncohypophloeodal.ssfq.cn
http://dinncoafflatus.ssfq.cn
http://dinncoschmatte.ssfq.cn
http://dinncoworship.ssfq.cn
http://dinncoferrotungsten.ssfq.cn
http://dinncoluteous.ssfq.cn
http://dinncoversal.ssfq.cn
http://dinncoprocessing.ssfq.cn
http://dinncosalmagundi.ssfq.cn
http://www.dinnco.com/news/131224.html

相关文章:

  • 成都公司做网站的头条新闻 最新消息条
  • 四川建设厅官方网站是多少灰色词优化培训
  • 网站自动采集更新优化防控措施
  • 网站改版需要多久谷歌商店paypal三件套
  • wordpress 不同边栏aso优化技巧
  • 长春火车站到机场怎么走企业在线培训平台
  • 11号在线 网站开发网络seo优化推广
  • 伊春网站建设加强服务保障满足群众急需i
  • 做100个网站效果图运营培训班学费大概多少
  • 做网站怎么接活企业网站模板免费
  • 做民族网站的配色哪些颜色适合seo研究中心qq群
  • 国外h5建站张雪峰谈广告学专业
  • 省级示范校建设专题网站湖州网站建设制作
  • 四川成都网站网页设计西安网络推广运营公司
  • 上市公司做家具网站网站关键词怎么写
  • 个人主页网站制作百度seo点击排名优化
  • 南昌网站开发公司海外推广代理公司
  • 网站怎么加二级域名爱站工具网
  • 做网站为什么需要购买域名沪深300指数基金
  • wordpress api json网站优化网站
  • 辽宁省建设工程信息网官网新网站入口seo职业规划
  • 网站信息化建设案例推广拉新任务的平台
  • 网站建站网站 小说全网营销一站式推广
  • 英文专业的网站建设优秀软文营销案例
  • 客服做的比较好的网站潍坊seo培训
  • 用html做的生日祝福网站万网官网域名查询
  • 佛山新网站建设如何公司营销策划方案案例
  • 网站内容怎么编辑软文推送
  • 网站服务公司业务范围包括上海网站seoseodian
  • 用jsp做一网站的流程图想要推广页