MongoDB 有关实体映射具体应用及对查询的影响
1 创建实体的时候,可以用注解@Document 对实体进行设置,指定集合名字
/**
*
*/
package com.cfj.ceshi.entity; import org.springframework.data.mongodb.core.mapping.Document; @Document(collection="etlCheckInfo")
public class Contrast { private static final long serialVersionUID = 1L; private String checkId;
private String readNum;
private String volume;
private String weight; public String getCheckId() {
return checkId;
}
public void setCheckId(String checkId) {
this.checkId = checkId;
}
public String getReadNum() {
return readNum;
}
public void setReadNum(String readNum) {
this.readNum = readNum;
}
public String getVolume() {
return volume;
}
public void setVolume(String volume) {
this.volume = volume;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
} }
如果不用注解指定集合名称,在保存方法的时候也没有指定集合名称,那么第一次创建集合的时候,集合名字就是实体名字contrast
如果利用注解指定了集合名称,在保存或查询等方法的时候,则不需要显示指定集合名称,默认会保存实体被注解的集合名字中去
package com.cfj.ceshi.dao.impl; 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.Component; import com.cfj.ceshi.dao.UserDao;
import com.cfj.ceshi.entity.UserEntity;
import com.mongodb.WriteResult; @Component
public class UserDaoImpl implements UserDao{ @Autowired
private MongoTemplate mongoTemplate; @Override
public void saveUser(UserEntity user) {
mongoTemplate.save(user);
//mongoTemplate.save(user, "jihe01");//指定集合 } }
MongoDB 有关实体映射具体应用及对查询的影响的更多相关文章
- 8.2 使用Fluent API进行实体映射【Code-First系列】
现在,我们来学习怎么使用Fluent API来配置实体. 一.配置默认的数据表Schema Student实体 using System; using System.Collections.Gener ...
- 开源实体映射框架EmitMapper介绍
开源实体映射框架EmitMapper介绍 综述 EmitMapper是一个开源实体映射框架,地址:http://emitmapper.codeplex.com/. Emit ...
- EntityFramework 实体映射到数据库
EntityFramework实体映射到数据库 在Entity Framework Code First与数据表之间的映射方式实现: 1.Fluent API映射 通过重写DbContext上的OnM ...
- EF Code First:实体映射,数据迁移,重构(1)
一.前言 经过EF的<第一篇>,我们已经把数据访问层基本搭建起来了,但并没有涉及实体关系.实体关系对于一个数据库系统来说至关重要,而且EF的各个实体之间的联系,实体之间的协作,联合查询等也 ...
- EF Code First:实体映射
二.实体映射 实体与数据库的映射可以通过DataAnnotation与FluentAPI两种方式来进行映射: (一) DataAnnotation DataAnnotation 特性由.NET 3.5 ...
- MongoDB中的映射,限制记录和记录拼排序 文档的插入查询更新删除操作
映射 在 MongoDB 中,映射(Projection)指的是只选择文档中的必要数据,而非全部数据.如果文档有 5 个字段,而你只需要显示 3 个,则只需选择 3 个字段即可. find() 方法 ...
- JdbcTemplate实体映射
JdbcTemplate实体映射 如果你需要使用JdbcTemplate将查询的数据映射成Java POJO,那么这篇文章适合你. 一个例子入门 下面是一个将表中一行记录映射成Map的例子,也是Jdb ...
- 10.1.翻译系列:EF 6中的实体映射【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/configure-entity-mappings-using-fluent-api.a ...
- 【译】第23节---Fluent API - 实体映射
原文:http://www.entityframeworktutorial.net/code-first/configure-entity-mappings-using-fluent-api.aspx ...
随机推荐
- oracle exp 导出前执行分析计划
记录一下小小问题: 当作为一个dmp 库导出的时候.如果我们在之前进行 对用户下的所有表进行分析. 那么在导入的时候 会连同分析计划数据一并导入 imp 导入dmp文件报错 IMP-00017: ...
- 【django】另一种思路代替nginx 的rewrite
需求:访问xx.com 跳转到xx.com/index 修改setting 同级别的urls.py 文件 from django.conf.urls import include, url from ...
- Access viewchild from another component
https://stackoverflow.com/questions/50935728/access-viewchild-from-another-component =============== ...
- [USACO19FEB]Cow Dating——找规律
原题戳这里 题解 显然原题等价于让我们求这个式子\(\prod\limits_{i=l}^{r}(1-p_i)\sum\limits_{i=l}^{r}\frac{p_i}{1-p_i}\)的最大值是 ...
- golang mysql 模糊查询
db.SqlDB.Query("SELECT id,name FROM test_table where title name like CONCAT('%',?,'%');", ...
- SPI使用笔记ADS1259+AD5676
SPI的通信速率通常比较快.目前用到的ADS1259芯片,可以达到2-4MHz,可能可以更加快.一般spi都是从慢速开始调试,但是具体到某个芯片,应该核对芯片时序图,比如ti的ds1259,数据手册上 ...
- [BZOJ 1146] [CTSC2008]网络管理Network(树状数组+主席树)
题目描述 M公司是一个非常庞大的跨国公司,在许多国家都设有它的下属分支机构或部门.为了让分布在世界各地的N个部门之间协同工作,公司搭建了一个连接整个公司的通信网络.该网络的结构由N个路由器和N-1条高 ...
- Nginx 转发特点URL到指定服务
location ^~ /fs/ {#如https://xx.com/fs/upload 转发到文件服务器 proxy_pass http://127.0.0.1:8080/fs/; }
- 小米oj 判断是否为连乘数字串
判断是否为连乘数字串 序号:#32难度:非常难时间限制:1000ms内存限制:10M 描述 给出一个字符串S,判断S是否为连乘字符串. 连乘字符串定义为: 字符串拆分成若干数字,后面的数字(从第三个 ...
- jQuery系列(八):jQuery的位置信息
1.宽度和高度 (1):获取宽度 .width() 描述:为匹配的元素集合中获取第一个元素的当前计算宽度值.这个方法不接受任何参数..css(width) 和 .width()之间的区别是后者返回一个 ...