📄 sblogtypedao.java
字号:
package cn.hope.front.pojo.dao;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import org.apache.log4j.Logger;
import cn.hope.front.pojo.SBlogtype;
import cn.hope.front.pojo.base.BaseSBlogtypeDAO;
public class SBlogtypeDAO extends BaseSBlogtypeDAO {
Logger log = Logger.getLogger(TFileDAO.class.getName());
/**
* Default constructor. Can be used in place of getInstance()
*/
public SBlogtypeDAO () {}
/**
* 查找所有类型
*/
/*
public static void main(String[] args) {
// TODO Auto-generated method stub
SBlogtypeDAO sb=new SBlogtypeDAO();
try {
sb.searchBlogtype();
System.out.println(sb);
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
*/
public List searchBlogtype(Integer sbId) throws HibernateException {
List list=null;
String sqlStr = "select sblogtype from SBlogtype sblogtype where sblogtype.flag='0' ";
try {
initialize();
list= this.getSession().find(sqlStr);
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
return list;
}
public SBlogtype load(Integer stId) throws HibernateException {
try {
initialize();
return super.load(stId);
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
/**
* 添加数据方法
*
* @param MHtype
* @return int
* @throws HibernateException
*/
public Integer insert(SBlogtype sblogtype) throws HibernateException {
try {
initialize();
if (searchByName(sblogtype) == null){
this.save(sblogtype);
}
return searchByName(sblogtype);
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
public Integer searchByName(SBlogtype sblogtype) throws HibernateException {
String sqlKey = "select sblogtype.stId from SBlogtype sblogtype where sblogtype.flag='0' and sblogtype.stTitle='"
+sblogtype.getStTitle()+"'";
try {
initialize();
Query queryCnt = this.getSession().createQuery(
sqlKey.toString());
Integer i = (Integer)queryCnt.uniqueResult();
return i;
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -