**********************service层是******************************
public interface CategoryService extends BaseService<Category> {
// //这下面的方法可以抽象出一些公有的方法,因为几乎每一个模块都有
// public void save(Category category);//保存
//
// public void update(Category category);//更新
//
// public void delete(int id);//删除
//
// public Category query(int id);//查询单条数据
//
// public List<Category> queryAll();//查询所有数据
//查询类别信息,级联管理员,用类别的名称去查,加分页,page是要告诉我显示第几页,size是要告诉我每一页显示多少条数据
public List<Category> queryAllJoinAccount(String ctype,int page,int size);
//根据关键字查询总记录数
public long getCount(String ctype);
//根据ids删除多条记录
public void deleteByIds(String ids);
import com.server.advertise.model.Category;
import com.server.advertise.service.CategoryService;
/**
*
* 里面放的是模块自身的业务逻辑
*
*/
@Service("categoryService")
public class CategoryServiceImpl extends BaseServiceImpl<Category> implements CategoryService {
//查询热点类别什么的
//如果类里面没有构造方法,在这里也会有缺省的构造方法
public CategoryServiceImpl(){
super();//调用该类的构造方法,会调用父类的构造方法
}
public static void main(String[] args) {
new CategoryServiceImpl();
}
@SuppressWarnings("unchecked")
@Override
public List<Category> queryAllJoinAccount(String ctype,int page,int size) {
String hql = "from Category c left join fetch c.account where c.ctype like :ctype";
return getSession().createQuery(hql).setString("ctype", "%" + ctype + "%")
.setFirstResult((page-1)*size)
.setMaxResults(size)
.list();
}
@Override
public long getCount(String ctype) {
String hql = "select count(c) from Category c where c.ctype like :ctype";
return (Long) getSession().createQuery(hql).setString("ctype", "%"+ ctype +"%").uniqueResult();
}
@Override
public void deleteByIds(String ids) {
String hql = "delete from Category where cid in (" + ids + ")";
getSession().createQuery(hql).executeUpdate();
}
@Override
public long getCount() {
// TODO Auto-generated method stub
return 0;
}
@SuppressWarnings("unchecked")
@Override
public List<Category> queryJoin() {
String hql = "select c.cid,ctype,chot,coverImage,adId,adName,description,adCoverPath,adPath,adType from category c,advertise a where c.cid = a.cid";
return getSession().createSQLQuery(hql).list();
}
}