spring data mongodb中,如果对象中的属性不想加入到数据库字段中

时间:2023-11-22 22:17:44

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

 package ywzn.by.scity.service.pojo;

 import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date; import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field; @Document(collection="YpObjRelationPojo")
@CompoundIndexes({@CompoundIndex(name="objrelation",def="{'sourceid':1,'targetid':1}")})
public class YpObjRelationPojo implements Serializable { @Id
private String Id; // '主键id'
@Field("sourceid")
private String sourceId; //对象id
@Field("targetid")
private String targetId; //对象id
@Field("caseId")
private String caseId; //案件id
@Transient //配置透明属性
private int source; // '关系起点 不存数据库
@Transient
private int target; // '关系终点 不存数据库
@Field("relation")
private String relation; // '关系名称'
@Field("create_time")
private Date create_Time; // '创建时间' public YpObjRelationPojo(String id, String sourceid, String targetid,
String caseId, String relation, Date create_time) {
super();
this.Id = id;
this.sourceId = sourceid;
this.targetId = targetid;
this.caseId = caseId;
this.relation = relation;
this.create_Time = create_time;
} public YpObjRelationPojo(String id, String sourceid, String targetid,
String caseId, String relation) {
super();
this.Id = id;
this.sourceId = sourceid;
this.targetId = targetid;
this.caseId = caseId;
this.relation = relation;
} public YpObjRelationPojo() {
super();
} @Override
public String toString() {
return "YpObjRelationPojo [id=" + Id + ", sourceid=" + sourceId
+ ", targetid=" + targetId + ", caseId=" + caseId + ", source="
+ source + ", target=" + target + ", relation=" + relation
+ ", create_time=" + create_Time + "]";
} /**
* @return the id
*/
public String getId() {
return Id;
} /**
* @param id the id to set
*/
public void setId(String id) {
Id = id;
} /**
* @return the sourceId
*/
public String getSourceId() {
return sourceId;
} /**
* @param sourceId the sourceId to set
*/
public void setSourceId(String sourceId) {
this.sourceId = sourceId;
} /**
* @return the targetId
*/
public String getTargetId() {
return targetId;
} /**
* @param targetId the targetId to set
*/
public void setTargetId(String targetId) {
this.targetId = targetId;
} /**
* @return the caseId
*/
public String getCaseId() {
return caseId;
} /**
* @param caseId the caseId to set
*/
public void setCaseId(String caseId) {
this.caseId = caseId;
} /**
* @return the source
*/
public int getSource() {
return source;
} /**
* @param source the source to set
*/
public void setSource(int source) {
this.source = source;
} /**
* @return the target
*/
public int getTarget() {
return target;
} /**
* @param target the target to set
*/
public void setTarget(int target) {
this.target = target;
} /**
* @return the relation
*/
public String getRelation() {
return relation;
} /**
* @param relation the relation to set
*/
public void setRelation(String relation) {
this.relation = relation;
} /**
* @return the create_Time
*/
public Date getCreate_Time() {
return create_Time;
} /**
* @param create_Time the create_Time to set
*/
public void setCreate_Time(Date create_Time) {
this.create_Time = create_Time;
} }