⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u02sblogbo.java

📁 持久层hibernate技术使用的一个例子
💻 JAVA
字号:
package cn.hope.front.bo;

import java.util.Date;
import java.util.List;

import net.sf.hibernate.HibernateException;

import org.apache.log4j.Logger;
import cn.hope.front.pojo.SBlog;
import cn.hope.front.pojo.SBlogtype;
import cn.hope.front.pojo.Student;

import cn.hope.front.pojo.U02CommonListVO;

import cn.hope.front.pojo.dao.SBlogDAO;
import cn.hope.front.pojo.dao.SBlogtypeDAO;
import cn.hope.front.util.U02Page;




public class U02SBlogBO {
	Logger log = Logger.getLogger(U02SBlogBO .class.getName());

	SBlogDAO sblogDAO = new SBlogDAO();

	public List serachBlog(SBlog sblog,int start, int range) throws Exception {
		List list = null;
		try {
			list = sblogDAO.searchBlog(sblog,start,range);
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw new Exception(e);
		}
		return list;
	}
	public List select(SBlog sblog,Integer stid) throws Exception {
		List tf = null;
		try {
			tf = sblogDAO.select(sblog,stid);			
			
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw new Exception(e);
		}
		return tf;
	}/*
	public  int insert(SBlog sblog) throws Exception {
		int flag = 0;
		try {
			flag = sblogDAO.insert(sblog).intValue();
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw new Exception(e);
		}
		return flag;
	}*/
	public void delete(String[] a) throws HibernateException {
		sblogDAO.del(a);	
	}

	public U02CommonListVO serach(SBlog sblog, int start, boolean isEq)
	throws Exception {
		U02CommonListVO cl_vo = new U02CommonListVO();
		int range = 10;// 每页显示记录数
		int count = 0;// 总记录数
		List list = null;// 查询得到的结果集
		U02Page page = new U02Page();// 分页
		String fenyeStr = "";
		try {
			list = sblogDAO.search(sblog, start, range, isEq);
			count = sblogDAO.getCount();
			cl_vo.setRs(list);
			cl_vo.setCount(count);
			cl_vo.setStart(start);
			cl_vo.setRange(range);
		
			fenyeStr = page.fenye(cl_vo);
			cl_vo.setFenye(fenyeStr);
			cl_vo.setCurrentPage(page.getCurrentPage());
			cl_vo.setTotalPage(page.getTotalPage());
			cl_vo.setStartSub(page.getStartSub());
			cl_vo.setOverSub(page.getOverSub());
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw new Exception(e);
		}
		return cl_vo;
}
	public SBlog searchBy(Integer id) throws Exception {
		SBlog tf = null;
		try {
			tf = sblogDAO.searchBy(id);			
			
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw new Exception(e);
		}
		return tf;
	}
	public SBlog modify(SBlog sblog)throws Exception
	{
		
		try{	
			
			sblogDAO.modify(sblog);
		}
		catch(Exception e)
		{
			log.error(e);
			e.printStackTrace();
			throw new Exception(e);
		}
		return sblog;
	}
	/*------添加方法------*/
	public boolean insert(SBlog sblog,SBlogtype sblogtype) throws HibernateException {
		SBlogtypeDAO sbtDAO = new SBlogtypeDAO();
		SBlogDAO sbDAO = new SBlogDAO();
		String sTitle = sblog.getSbTitle().trim();
		int count = 0;
		try {
			count = sbDAO.searchByName(sTitle);
			if (count == 0){
				sblogtype.setFlag("0");
				sblog.setFlag("0");
				sblog.setSbDate(new Date());
				//String inputsb = sblog.getSbCon();
				sblog.setSbCon(sblog.getSbCon());
				sblog.setSbTitle(sTitle);
				Student st = new Student();//声明实体Student
				st.setSUsername("aaaa");//设+置用户名
				sblog.setStudent(st);//将用户名添加到数据库
				if (sblogtype.getStTitle()==null || sblogtype.getStTitle().equals("")){
					sblog.setSBlogtype(sbtDAO.load(sblogtype.getStId()));
				}
				else{
					sblogtype.setStTitle(sblogtype.getStTitle().trim());
					sblog.setSBlogtype(sbtDAO.load(sbtDAO.insert(sblogtype)));
				};
				sbDAO.insert(sblog);
				return true;
			}
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		}
		return false;
	}



	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -