zoukankan      html  css  js  c++  java
  • spring data mongodb中,如果对象中的属性不想加入到数据库字段中

    spring data mongodb中,如果对象中的属性不想加入到数据库字段中,可加@Transient注解,声明为透明属性

    spring data mongodb 官网帮助文档

    http://www.boyunjian.com/javadoc/org.springframework.data/spring-data-mongodb/1.2.3.RELEASE/_/org/springframework/data/mongodb/core/query/Criteria.html#all(java.util.Collection

      1 package ywzn.by.scity.service.pojo;
      2 
      3 import java.io.Serializable;
      4 import java.sql.Timestamp;
      5 import java.util.Date;
      6 
      7 import org.springframework.data.annotation.Id;
      8 import org.springframework.data.annotation.Transient;
      9 import org.springframework.data.mongodb.core.index.CompoundIndex;
     10 import org.springframework.data.mongodb.core.index.CompoundIndexes;
     11 import org.springframework.data.mongodb.core.mapping.DBRef;
     12 import org.springframework.data.mongodb.core.mapping.Document;
     13 import org.springframework.data.mongodb.core.mapping.Field;
     14 
     15 
     31 @Document(collection="YpObjRelationPojo")
     32 @CompoundIndexes({@CompoundIndex(name="objrelation",def="{'sourceid':1,'targetid':1}")})
     33 public class YpObjRelationPojo implements Serializable {
     34 
     35     @Id
     36     private String Id;                    // '主键id'
     37     @Field("sourceid")
     38     private String sourceId;            //对象id
     39     @Field("targetid")
     40     private String targetId;            //对象id    
     41     @Field("caseId")
     42     private String caseId;                //案件id
     43     @Transient                            //配置透明属性
     44     private int source;                    // '关系起点       不存数据库
     45     @Transient
     46     private int target;                    // '关系终点    不存数据库
     47     @Field("relation")
     48     private String relation;            // '关系名称'
     49     @Field("create_time")
     50     private Date create_Time;            // '创建时间'
     51     
     52     public YpObjRelationPojo(String id, String sourceid, String targetid,
     53             String caseId, String relation, Date create_time) {
     54         super();
     55         this.Id = id;
     56         this.sourceId = sourceid;
     57         this.targetId = targetid;
     58         this.caseId = caseId;
     59         this.relation = relation;
     60         this.create_Time = create_time;
     61     }
     62     
     63     public YpObjRelationPojo(String id, String sourceid, String targetid,
     64             String caseId, String relation) {
     65         super();
     66         this.Id = id;
     67         this.sourceId = sourceid;
     68         this.targetId = targetid;
     69         this.caseId = caseId;
     70         this.relation = relation;
     71     }
     72 
     73     public YpObjRelationPojo() {
     74         super();
     75     }
     76 
     77     
     78     @Override
     79     public String toString() {
     80         return "YpObjRelationPojo [id=" + Id + ", sourceid=" + sourceId
     81                 + ", targetid=" + targetId + ", caseId=" + caseId + ", source="
     82                 + source + ", target=" + target + ", relation=" + relation
     83                 + ", create_time=" + create_Time + "]";
     84     }
     85 
     86     /**
     87      * @return the id
     88      */
     89     public String getId() {
     90         return Id;
     91     }
     92 
     93     /**
     94      * @param id the id to set
     95      */
     96     public void setId(String id) {
     97         Id = id;
     98     }
     99 
    100     /**
    101      * @return the sourceId
    102      */
    103     public String getSourceId() {
    104         return sourceId;
    105     }
    106 
    107     /**
    108      * @param sourceId the sourceId to set
    109      */
    110     public void setSourceId(String sourceId) {
    111         this.sourceId = sourceId;
    112     }
    113 
    114     /**
    115      * @return the targetId
    116      */
    117     public String getTargetId() {
    118         return targetId;
    119     }
    120 
    121     /**
    122      * @param targetId the targetId to set
    123      */
    124     public void setTargetId(String targetId) {
    125         this.targetId = targetId;
    126     }
    127 
    128     /**
    129      * @return the caseId
    130      */
    131     public String getCaseId() {
    132         return caseId;
    133     }
    134 
    135     /**
    136      * @param caseId the caseId to set
    137      */
    138     public void setCaseId(String caseId) {
    139         this.caseId = caseId;
    140     }
    141 
    142     /**
    143      * @return the source
    144      */
    145     public int getSource() {
    146         return source;
    147     }
    148 
    149     /**
    150      * @param source the source to set
    151      */
    152     public void setSource(int source) {
    153         this.source = source;
    154     }
    155 
    156     /**
    157      * @return the target
    158      */
    159     public int getTarget() {
    160         return target;
    161     }
    162 
    163     /**
    164      * @param target the target to set
    165      */
    166     public void setTarget(int target) {
    167         this.target = target;
    168     }
    169 
    170     /**
    171      * @return the relation
    172      */
    173     public String getRelation() {
    174         return relation;
    175     }
    176 
    177     /**
    178      * @param relation the relation to set
    179      */
    180     public void setRelation(String relation) {
    181         this.relation = relation;
    182     }
    183 
    184     /**
    185      * @return the create_Time
    186      */
    187     public Date getCreate_Time() {
    188         return create_Time;
    189     }
    190 
    191     /**
    192      * @param create_Time the create_Time to set
    193      */
    194     public void setCreate_Time(Date create_Time) {
    195         this.create_Time = create_Time;
    196     }
    197 
    198 }
  • 相关阅读:
    eclipse下c/cpp " undefined reference to " or "launch failed binary not found"问题
    blockdev 设置文件预读大小
    宝宝语录
    CentOS修改主机名(hostname)
    subprocess报No such file or directory
    用ldap方式访问AD域的的错误解释
    英特尔的VTd技术是什么?
    This virtual machine requires the VMware keyboard support driver which is not installed
    Linux内核的文件预读详细详解
    UNP总结 Chapter 26~29 线程、IP选项、原始套接字、数据链路访问
  • 原文地址:https://www.cnblogs.com/bornteam/p/4157211.html
Copyright © 2011-2022 走看看