数据库中数据为空,转换为对象时的处理

基本数据类型中,如果数据库中的数据为空,需要进行转换

以hibernate使用为例

查询对象VO类展示

public class ArticleDataVO {
	/** 文章id */
	protected String newsId;
	/** 阅读次数 */
	protected long reads;
	/** 阅读人数 */
	protected long readers;
	/** 评论数 */
	protected long comments;
	/** 点赞数 */
	protected long praises;
	/** 分享数 */
	protected long shares;
	/** 收藏数 */
	protected long favorites;

	public ArticleDataVO() {}

	/**
	 * WEB文章
	 * 
	 * @param newsId
	 *            文章id
	 * @param reads
	 *            阅读次数
	 * @param readers
	 *            阅读人数
	 **/
	public ArticleDataVO(String newsId, Number reads, Number readers) {
		this.newsId = newsId;
		this.reads = reads == null ? 0 : reads.longValue();
		this.readers = readers == null ? 0 : readers.longValue();
	}

	/**
	 * APP文章
	 * 
	 * @param newsId
	 *            文章id
	 * @param reads
	 *            阅读次数
	 * @param readers
	 *            阅读人数
	 * @param comments
	 *            评论数
	 * @param praises
	 *            点赞数
	 * @param shares
	 *            分享数
	 * @param favorites
	 *            收藏数
	 */
	public ArticleDataVO(String newsId, Number reads, Number readers, Number comments, Number praises, Number shares,
			Number favorites) {
		this.newsId = newsId;
		this.reads = reads == null ? 0 : reads.longValue();
		this.readers = readers == null ? 0 : readers.longValue();
		this.comments = comments == null ? 0 : comments.longValue();
		this.praises = praises == null ? 0 : praises.longValue();
		this.shares = shares == null ? 0 : shares.longValue();
		this.favorites = favorites == null ? 0 : favorites.longValue();
	}

	/**
	 * Get the {@link #newsId}.
	 * 
	 * @return the newsId
	 */
	public String getNewsId() {
		return newsId;
	}

	/**
	 * Set the {@link #newsId}.
	 * 
	 * @param newsId
	 *            the newsId to set
	 */
	public void setNewsId(String newsId) {
		this.newsId = newsId;
	}

	/**
	 * Get the {@link #reads}.
	 * 
	 * @return the reads
	 */
	public long getReads() {
		return reads;
	}

	/**
	 * Set the {@link #reads}.
	 * 
	 * @param reads
	 *            the reads to set
	 */
	public void setReads(long reads) {
		this.reads = reads;
	}

	/**
	 * Get the {@link #readers}.
	 * 
	 * @return the readers
	 */
	public long getReaders() {
		return readers;
	}

	/**
	 * Set the {@link #readers}.
	 * 
	 * @param readers
	 *            the readers to set
	 */
	public void setReaders(long readers) {
		this.readers = readers;
	}

	/**
	 * Get the {@link #comments}.
	 * 
	 * @return the comments
	 */
	public long getComments() {
		return comments;
	}

	/**
	 * Set the {@link #comments}.
	 * 
	 * @param comments
	 *            the comments to set
	 */
	public void setComments(long comments) {
		this.comments = comments;
	}

	/**
	 * Get the {@link #praises}.
	 * 
	 * @return the praises
	 */
	public long getPraises() {
		return praises;
	}

	/**
	 * Set the {@link #praises}.
	 * 
	 * @param praises
	 *            the praises to set
	 */
	public void setPraises(long praises) {
		this.praises = praises;
	}

	/**
	 * Get the {@link #shares}.
	 * 
	 * @return the shares
	 */
	public long getShares() {
		return shares;
	}

	/**
	 * Set the {@link #shares}.
	 * 
	 * @param shares
	 *            the shares to set
	 */
	public void setShares(long shares) {
		this.shares = shares;
	}

	/**
	 * Get the {@link #favorites}.
	 * 
	 * @return the favorites
	 */
	public long getFavorites() {
		return favorites;
	}

	/**
	 * Set the {@link #favorites}.
	 * 
	 * @param favorites
	 *            the favorites to set
	 */
	public void setFavorites(long favorites) {
		this.favorites = favorites;
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值