首页>代码>Hibernate+Spring+Spring MVC+ExtJs开发新闻发布后台管理系统,前端通过bootstrap实现>/Platform/src/org/platform/system/client/service/news/NewsContentClientService.java
package org.platform.system.client.service.news;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.platform.system.client.dao.news.NewsContentClientDao;
import org.platform.system.entity.news.NewsContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 资讯内容客户端服务。
*
* @author 钱佳明。
*
*/
@Service
public class NewsContentClientService implements NewsContentClientDao {
/**
* Session工厂。
*/
@Autowired
public SessionFactory sessionFactory;
/**
* 返回资讯内容数据。
*
* @param id
* 资讯内容编号。
* @return 资讯内容数据。
*/
@Override
public NewsContent get(Integer id) {
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
try {
NewsContent newsContent = (NewsContent) session.get(
NewsContent.class, id);
transaction.commit();
return newsContent;
} catch (Exception e) {
if (transaction != null) {
transaction.rollback();
}
return null;
} finally {
session.close();
}
}
/**
* 返回资讯内容数据。
*
* @param id
* 所属栏目编号。
* @param start
* 开始记录。
* @param limit
* 限制记录。
* @return 资讯内容数据。
*/
@Override
@SuppressWarnings("unchecked")
public List<NewsContent> list(Integer id, Integer start, Integer limit) {
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
try {
String hql = "from NewsContent newsContent where newsContent.newsCategory.id = "
+ id + " order by newsContent.editDate desc";
Query query = session.createQuery(hql);
query.setFirstResult(start);
query.setMaxResults(limit);
List<NewsContent> list = query.list();
transaction.commit();
return list;
} catch (Exception e) {
e.printStackTrace();
if (transaction != null) {
transaction.rollback();
}
return null;
} finally {
session.close();
}
}
}
最近下载更多
benbosn LV15
2022年8月31日
xxxhhh1314 LV7
2022年1月9日
zhllzhll LV7
2021年12月8日
wurongchuyu LV5
2021年5月14日
aybk666 LV1
2021年4月5日
Jayant-YXY LV6
2021年2月20日
maicuminte LV2
2020年6月22日
倪卟懂 LV18
2020年5月26日
jaonsang LV25
2020年3月21日
hzq1498279624 LV2
2020年3月13日
最近浏览更多
krispeng LV15
5月29日
educationAAA LV11
2024年6月23日
lmj12345 LV2
2024年5月19日
WBelong LV8
2023年12月27日
微信网友_6784866726285312
2023年12月26日
暂无贡献等级
pangzhihui LV14
2023年5月11日
Mr_VVcat LV9
2023年4月19日
泓鼎168 LV20
2023年4月14日
微信网友_6403344757608448
2023年3月24日
暂无贡献等级
hesu2020 LV1
2023年3月18日

