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

隆回网站建设制作广东seo点击排名软件哪家好

隆回网站建设制作,广东seo点击排名软件哪家好,安徽城乡建设厅官网站,国家网站后缀文章目录前言一、搭建项目二、开始编写java代码1. 新增2.查询3. 修改4. 删除5.根据条件查询6. 关联查询7. 索引相关总结前言 MongoTemplate 相关操作 CRUD,聚合查询等; 一、搭建项目 springboot项目创建引入mongo 依赖docker 安装好mongo数据库配置yml 链接mongo spring:dat…

文章目录

  • 前言
  • 一、搭建项目
  • 二、开始编写java代码
    • 1. 新增
    • 2.查询
    • 3. 修改
    • 4. 删除
    • 5.根据条件查询
    • 6. 关联查询
    • 7. 索引相关
  • 总结


前言

MongoTemplate 相关操作 CRUD,聚合查询等;


一、搭建项目

  • springboot项目创建
  • 引入mongo 依赖
  • docker 安装好mongo数据库
  • 配置yml 链接mongo
spring:data:mongodb:host: 127.0.0.1port: 27017database: test

pom/gradle MongoTemplate 版本: 2.6.3

spring-boot-starter-data-mongodb

mongo可视化工具 robo3t
链接工具
springboot yml配置

二、开始编写java代码

1. 新增

  @AutowiredMongoTemplate mongoTemplate;@Testvoid add() {List<ApplicationEntity> applicationEntityList = init();Collection<ApplicationEntity> applicationEntities = mongoTemplate.insert(applicationEntityList, ApplicationEntity.class);log.info("存储成功: {}", JSONUtil.toJsonStr(mongoTemplate.findAll(ApplicationEntity.class)));}private List<ApplicationEntity> init() {List<ApplicationEntity> applicationEntityList = CollectionUtil.newArrayList();for (int i = 0; i < 2; i++) {String id = IdUtil.fastSimpleUUID();String name = "第" + RandomUtil.randomNumbers(2) + "个应用";ApplicationEntity applicationEntity = ApplicationEntity.builder().id(id).name(name).orgName(name).icon("https://www.baidu.com").status(RandomUtil.randomBoolean() ? "启用" : "禁用").type("application").build();applicationEntityList.add(applicationEntity);}return applicationEntityList;}

实体具体内容
实体内容

2.查询

 @AutowiredMongoTemplate mongoTemplate;@Testvoid queryField() {Query query1 = new Query();query1.fields().include("orgName", "name");List<ApplicationEntity> applicationEntities = mongoTemplate.find(query1, ApplicationEntity.class);System.out.println(JSONUtil.toJsonStr(applicationEntities));}

1 include 查询指定字段,可以不指定,查询所有字段
2 ApplicationEntity 对应mongo数据库中的一个document

3. 修改

找到要修改的,并修改

  @Testvoid update() {ApplicationDto applicationDto = new ApplicationDto();applicationDto.setId("b8cbf05d102e454784ab85f23704bfb7");applicationDto.setName("测试");applicationDto.setStatus("启用");applicationDto.setIcon("www.tupian");Query query = new Query(Criteria.where("id").is(applicationDto.getId()));Update update = new Update();update.set("fileUrl", applicationDto.getIcon());update.set("name", applicationDto.getName());update.set("status", applicationDto.getStatus());mongoTemplate.updateFirst(query, update, ApplicationEntity.class);List<ApplicationEntity> all = mongoTemplate.findAll(ApplicationEntity.class);System.out.println(JSONUtil.toJsonStr(all));}

4. 删除

找到并删除

    Criteria criteria = Criteria.where("pid").is(applicationDto.getId());mongoTemplate.findAllAndRemove(new Query(criteria), MenuNavigationEntity.class);

5.根据条件查询

相当于
select * from a where id=1 or id =2;

   @Testvoid queryCondition() {Query query1 = new Query(new Criteria().orOperator(Criteria.where("id").is("923406"), Criteria.where("id").is("3518177")));List<MenuNavigationEntity> menuNavigationEntityList = mongoTemplate.find(query1, MenuNavigationEntity.class);System.out.println(JSONUtil.toJsonStr(menuNavigationEntityList));}

6. 关联查询

相当于
select *
from a
left join b on a.id = b.pid;

    @Testvoid queryLink() {LookupOperation lookupOperation = LookupOperation.newLookup().from("menu_navigation")// 副表名称.localField("_id")// 主表关联字段.foreignField("pid")// 副表关联字段.as("menu_navigation");// 副表别名// 聚合条件Aggregation aggregation = Aggregation.newAggregation(lookupOperation,Aggregation.match(Criteria.where("menu_navigation.pid")// 副表关联的主表条件.is("b8cbf05d102e454784ab85f23704bfb7")));AggregationResults<JSONObject> aggregate = mongoTemplate.aggregate(aggregation, ApplicationEntity.class,JSONObject.class);// 条件  主表类型  结果类型List<JSONObject> mappedResults = aggregate.getMappedResults();System.out.println(JSONUtil.toJsonStr(mappedResults));}

7. 索引相关

    @Testvoid index() {MongoCollection<Document> collection = mongoTemplate.getCollection("application");collection.createIndex(new Document("id", "hashed"), new IndexOptions().name("index_id"));// 唯一索引collection.createIndex(new Document("id", "hashed"), new IndexOptions().unique(true).name("index_id"));// 删除指定索引collection.dropIndex("index_id");// 删除所有索引collection.dropIndexes();}

总结

主要是展示了 MongoTemplate 中的CRUD的常规操作和 关联查询,之后会继续学习~~
还有个问题,就是我无法从已经标记为 文档的实体中获取 集合名称嘛? 现在我的代码中的集合名称都是字符串
还有就是字段名称也都是字符串,可以从这个 document 中获取嘛?
实体

http://www.hengruixuexiao.com/news/19392.html

相关文章:

  • 广州那家做网站最好搭建网站工具
  • dns是不是做网站用的广州疫情最新动态
  • 制作网页教程简单建站合肥网络公司seo
  • 北京好的做网站的公司有哪些软文广告成功案例
  • 天津广告公司网站建设百度网址大全首页
  • 微网站背景图片网站外链的优化方法
  • 管理学习网站定制网站制作公司
  • crm管理系统都有哪些安卓优化大师手机版
  • 网站加百度商桥线上销售平台都有哪些
  • 新网站建设方案ppt网站seo资讯
  • 做微博网站好不好企业网站关键词优化
  • 广东微信网站制作多少钱百度账号中心
  • 做外包的网站有哪些问题南昌seo全网营销
  • seo优秀网站百度推广客户端app下载
  • 湖南做网站廊坊网络推广优化公司
  • 响应式网站建设平台链接制作
  • 做网站时管理员权限的页面提高工作效率的重要性
  • 简洁大气企业网站模板优化站点
  • 电子商务网站建设项目规划书西安网络seo公司
  • 怎么用ps做网站品牌营销
  • 自己做整个网站的流程手机上怎么制作网页
  • 专业的电商网站建设公司安徽360优化
  • 网站建设属于ITseo站长工具查询
  • 沧州网站建设的集成商网络推广员是干嘛的
  • 静态做头像的网站最近10个新闻
  • 怎么做网站seo优化seo搜索引擎优化是什么
  • 网页制作和设计实验报告seo赚钱方式
  • 百度收录什么网站流量推广怎么做
  • 如何创新网站建设模式千锋教育的官网
  • 一般网站建设多少钱谷歌账号注册