package bdqn.newsManageServlet.Service.Impl; import java.util.List; import bdqn.newsManageServlet.Dao.categoryTBDao; import bdqn.newsManageServlet.Dao.newsTbDao; import bdqn.newsManageServlet.Dao.Impl.categoryTBDaoImpl; import bdqn.newsManageServlet.Dao.Impl.newsTbDaoImpl; import bdqn.newsManageServlet.Service.categoryTBService; import bdqn.newsManageServlet.entity.categoryTB; import bdqn.newsManageServlet.entity.newsTb; public class categoryTBServiceImpl implements categoryTBService { /** * 1.先判断该类别下是否有新闻 * 有,提示错误 0 * 2.没有,删除类别! * 成功,提示成功 1 * 失败,提示失败-1 */ //创建数据访问层的对象 categoryTBDao cgDao=new categoryTBDaoImpl(); //删除 public int delCategory(int cgID) { int rel=-1; //1.调用新闻数据访问层的查询方法,根据类别ID查询新闻 newsTbDao newsDao=new newsTbDaoImpl(); List<newsTb> newslist=newsDao.getnewsAllById(cgID); if(newslist.size()>0){ //有新闻 rel=0; }else{ //没有新闻 rel=cgDao.delCategory(cgID); } return rel; } // 查询所有的类别 public List<categoryTB> getCategoryTBAll() { return cgDao.getCategoryTBAll(); } // 添加新闻类别 public int addCategory(categoryTB cate) { return cgDao.addCategory(cate); } // 修改新闻类别,根据类别 public int updateCategory(categoryTB cate) { return cgDao.updateCategory(cate); } // 获取类别,根据名称 public categoryTB getCateByName(String catename) { return cgDao.getCateByName(catename); } // 获取类别,根据id public categoryTB getCateById(int id) { return cgDao.getCateById(id); } //根据类别名查询类别的id public categoryTB getCategoryIdByName(String categoryName) { return cgDao.getCategoryIdByName(categoryName); } }