📄 newstservice.java
字号:
package service;
import java.util.*;
import po.news.*;
import hibernate.*;
import org.hibernate.*;
public class NewstService {
/*
* 新闻发布:添加一条新闻
*/
public static boolean addNews(Newst news)
{
NewstDAO dao = new NewstDAO();
try{
Session session=dao.getSession();
Transaction tx=session.beginTransaction();
dao.save(news);
session.flush();
tx.commit();
return true;
}catch(HibernateException e){
return false;
}finally{
try {
dao.getSession().close();
} catch (Exception e) {
}
}
}
/*
* 新闻列表显示
*/
public static List newsList(Newst news)
{
NewstDAO dao = new NewstDAO();
try{
List list=dao.findByExample(news);
return list;
}catch(HibernateException e){
return null;
}finally{
try {
dao.getSession().close();
} catch (Exception e) {
}
}
}
/*
* 新闻内容显示
*/
public static Newst getNewsContent(Integer newstId)
{
NewstDAO dao = new NewstDAO();
try{
Newst news=dao.findById(newstId);
return news;
}catch(HibernateException e){
return null;
}finally{
try {
dao.getSession().close();
} catch (Exception e) {
}
}
}
/*
* 新闻查询功能,返回新闻列表
*/
public static List newsSearch(String author, String title)
{
NewstDAO dao = new NewstDAO();
try{
List newsList=dao.findByHQL(author,title);
return newsList;
}catch(HibernateException e){
return null;
}finally{
try {
dao.getSession().close();
} catch (Exception e) {
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -