基本数据类型中,如果数据库中的数据为空,需要进行转换
以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;
}