ITeye博客

简单常用方法接口_2

hanjava · 2012-02-16 16:06 · java 应用 · 编程语言 · Markdown

第三步,定义具体dao接口 package dao;

import bean.entity.Clothes;

public interface ClothesDao extends GenericDao<Clothes,Integer> {

} 第四步,实现dao package imp;

import bean.entity.Clothes; import dao.ClothesDao;

public class ClothesDaoImpl extends GenericHibernateDaoImpl<Clothes,Integer> implements ClothesDao{

} 第五步,定义业务层service接口 package zip;

import java.util.List;

import tool.PageBean; import bean.entity.Clothes;

public interface ClothesService {

/**
 * 增加衣服
 * @param emp
 * @return boolean
 */
public boolean addClothes(Clothes c);

/**
 * 获得所有厂服订制详细信息
 * @return List
 */
public List queryClothes();

/**
 * 根据编号获得订制的厂服
 * @param cid
 * @return
 */
public Clothes getClothes(String htl);

/**
 * 更新厂服订制
 * @param c
 * @return
 */
public void updateClothes(Clothes c);

/**
 * 删除订制
 * @param cid
 */
public void deleteClothes(Clothes c);

/**
 * 分页查询
 * 
 * @param currentPage
 *            当前第几页
 * @param pageSize
 *            每页大小
 * @return 封闭了分页信息(包括记录集list)的Bean
 */
public PageBean queryForPage(int pageSize, int currentPage);

} 第六步,实现业务层 package imp;

import java.util.List;

import tool.PageBean; import zip.ClothesService; import bean.entity.Clothes; import dao.ClothesDao;

public class ClothesServiceImpl implements ClothesService{

private ClothesDao clothesDao;

public ClothesDao getClothesDao() {
	return clothesDao;
}
public void setClothesDao(ClothesDao clothesDao) {
	this.clothesDao = clothesDao;
}

public boolean addClothes(Clothes c) {
	// TODO Auto-generated method stub
	return clothesDao.add(c);
}

public List queryClothes() {
	// TODO Auto-generated method stub
	return null;//dao.queryClothes();
}

public Clothes getClothes(String hql) {
	// TODO Auto-generated method stub
	return clothesDao.findById(hql);
}

public void updateClothes(Clothes c) {
	// TODO Auto-generated method stub
	//dao.updateClothes(c);
	clothesDao.update(c);
}

public void deleteClothes(Clothes c) {
	// TODO Auto-generated method stub
	clothesDao.delete(c);
}

public PageBean queryForPage(int pageSize, int currentPage) {
	// TODO Auto-generated method stub
	//查询语句
	final String hql = "select c.cid,e.eid,e.ename,e.esex,e.edept,c.longSleeve,c.shortSleeve,c.csize,c.cremark " +
							"from Clothes as c inner join c.employee as e where e.eid=c.employee.eid";
	//int allRow = dao.getAllRowCount(hql);//总记录数
	int allRow = clothesDao.getTotal(hql);//总记录数
	int totalPage = PageBean.countTotalPage(pageSize, allRow);//总页数
	final int offset = PageBean.countOffset(pageSize, currentPage);//当前页开始记录
	final int length = pageSize;//每页记录数
	final int pageNo = PageBean.countCurrentPage(currentPage);
	//List list = dao.queryForPage(hql, offset, length);//"一页"的记录
	List list = clothesDao.findList(hql,offset, length);//"一页"的记录
	
	//把分页信息保存到Bean中
	PageBean pageBean = new PageBean();
	pageBean.setPageSize(pageSize);
	pageBean.setCurrentPage(pageNo);
	pageBean.setAllRow(allRow);pageBean.setTotalPage(totalPage);
	pageBean.setList(list);
	pageBean.init();
	return pageBean;
}

} 第七步,控制层实现action public ActionForward deleteClothes(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

	String cid = request.getParameter("cid");
	System.out.println(cid + "*******cid");
	Clothes c = new Clothes();
	c.setCid(Integer.valueOf(cid));
	clothesService.deleteClothes(c);

	//删除成功与否回到结果页面
	return this.queryClothes(mapping, form, request, response);
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。