分享

sql搜索24小时内的热贴

 走墨 2014-09-23
@SuppressWarnings("unchecked")
public List<MdBarTopic> getHotTopicList(String barId) {
try {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowDay = sdf.format(now);
Date start = sdf.parse(nowDay.split(" ")[0]+" 00:00:00");
Date end =  sdf.parse(nowDay.split(" ")[0]+" 23:59:59");
ArrayList<MdBarTopic> list = new ArrayList<MdBarTopic>();
List<Map> data = this.getNamedQuery("sdBar::getHotTopicList::query", barId, start, end);
if(data!=null&&data.size()>0){
for(Map map : data){
MdBarTopic mdBarTopic = new MdBarTopic();
mdBarTopic.setReplyCount(Integer.parseInt(map.get("REPLY_COUNT").toString()));
mdBarTopic.setTitle((String) map.get("TITLE"));
mdBarTopic.setTopicId((String) map.get("TOPIC_ID"));
list.add(mdBarTopic);
}
}
return list;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}


sdBar::getHotTopicList::query:


oracle


SELECT * FROM MD_BAR_TOPIC WHERE BAR_ID = ? AND CRE_TIME > ? AND CRE_TIME < ? and rownum<6 ORDER BY REPLY_COUNT DESC 


mysql:

SELECT * FROM MD_BAR_TOPIC WHERE BAR_ID = ? AND CRE_TIME > ? AND CRE_TIME < ? ORDER BY REPLY_COUNT DESC LIMIT 0,5 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约