mongo数据库中一条记录中某个属性是数组情形时 数据结构的定义

package entity;

import java.util.Date;

import com.mongodb.BasicDBList;
import com.mongodb.DBObject;

public class CommonEditEntity {

/** 数据库中查询记录结果 */
private DBObject record;

/** 数据库默认id */
private String _id;

/** 项目id */
private String project_id;

/** 项目名称 */
private String project_name;

/** 项目创建时间 */
private Date start_time;

/** 下一个项目激活时间 */
private Date end_time;

/** 项目激活的状态 */
private String status;

/** 标题内容 */
private ProContent[] proContent;

/**
* @return the record
*/
public DBObject getRecord() {
return record;
}

/**
* @param record the record to set
*/
public void setRecord(DBObject record) {
this.record = record;
}

/**
* 设置 数据库默认id
* @return the _id
*/
public String get_id() {
if (this._id == null && record.get("_id") != null) {
this._id = record.get("_id").toString();
}
return _id;
}

/**
* 返回 数据库默认id
* @param _id the _id to set
*/
public void set_id(String _id) {
this._id = _id;
}

/**
* 返回 项目id
* @return the project_id
*/
public String getProject_id() {
if (this.project_id == null && record.get("project_id") != null) {
this.project_id = record.get("project_id").toString();
}
return project_id;
}


/**
* 设置 项目id
* @param project_id the project_id to set
*/
public void setProject_id(String project_id) {
this.project_id = project_id;
}

/**
* 返回 项目名称
* @return the project_name 项目名称
*/
public String getProject_name() {
if (this.project_name == null && record.get("project_name") != null) {
this.project_name = record.get("project_name").toString();
}
return project_name;
}

/**
* 设置 项目名称
* @param project_name the project_name to set 项目名称
*/
public void setProject_name(String project_name) {
this.project_name = project_name;
}


/**
* 返回 项目创建时间
* @return the start_time 项目创建时间
*/
public Date getStart_time() {
if (this.start_time == null && record.get("start_time") != null) {
this.start_time = new Date(Long.parseLong(record.get("start_time").toString()));
}
return start_time;
}

/**
* 设置 项目创建时间
* @param start_time the start_time to set 项目创建时间
*/
public void setStart_time(Date start_time) {

this.start_time = start_time;
}


/**
* 返回 下一个项目激活时间
* @return the end_time 下一个项目激活时间
*/
public Date getEnd_time() {
if (this.end_time == null && record.get("end_time") != null) {
this.end_time = new Date(Long.parseLong(record.get("end_time").toString()));
}
return end_time;
}


/**
* 设置 下一个项目激活时间
* @param end_time the end_time to set 下一个项目激活时间
*/
public void setEnd_time(Date end_time) {
this.end_time = end_time;
}


/**
* 返回 项目激活的状态
* @return the status 项目激活的状态
*/
public String getStatus() {
if (this.status == null && record.get("status") != null) {
this.status = record.get("status").toString();
}
return status;
}

/**
* 设置 项目激活的状态
* @param status the status to set 项目激活的状态
*/
public void setStatus(String status) {
this.status = status;
}


/**
* 返回 标题内容
* @return the proContent 标题内容
*/
public ProContent[] getProContent() {
if (this.proContent == null && record.get("title_content") != null) {
BasicDBList itemList = (BasicDBList)record.get("title_content");
this.proContent = new ProContent[itemList.size()];
for (int i = 0; i < itemList.size(); i++) {
this.proContent[i] = new ProContent();
this.proContent[i].record = (DBObject)itemList.get(i);
}
}
return proContent;
}

/**
* 设置 标题内容
* @param proContent the proContent to set 标题内容
*/
public void setProContent(ProContent[] proContent) {
this.proContent = proContent;
}

class ProContent{

/** 数据库中查询记录结果 */
private DBObject record;

/** 标题 */
private String title;

/** 内容 */
private String content;

/**
* 返回 数据库中查询记录结果
* @return 数据库中查询记录结果
*/
public DBObject getRecord() {
return record;
}

/**
* 设置 数据库中查询记录结果
* @param record 数据库中查询记录结果
*/
public void setRecord(DBObject record) {
this.record = record;
}

/**
* 返回 标题
* @return the title
*/
public String getTitle() {
if (this.title == null && record.get("title") != null) {
this.title = record.get("title").toString();
}
return title;
}

/**
* 设置 标题
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}

/**
* 返回 内容
* @return the content
*/
public String getContent() {
if (this.content == null && record.get("content") != null) {
this.content = record.get("content").toString();
}
return content;
}

/**
* 设置 内容
* @param content the content to set
*/
public void setContent(String content) {
this.content = content;
}


}

}

原文地址:https://www.cnblogs.com/Wen-yu-jing/p/3792250.html