4 月更文挑战第22天 | 基于java的校园二手商品交易系统的开发11

324 阅读2分钟

一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第22天,点击查看活动详情

这个章节主页是校园二手商品交易系统的service层的代码。

public PageBean<Admin> findAllAdminInfo(int currPage) {
        PageBean<Admin> pageBean=new PageBean<Admin>();
        //封装当前页
        pageBean.setCurrPage(currPage);
        //封装每页记录数
        int pageSize=3;
        pageBean.setPageSize(pageSize);
        //封装总记录数
        int totalCount=this.iAdminInfoDao.findAdminCount();
        pageBean.setTotalCount(totalCount);
        //封装总页数
        double tc=totalCount;
        Double num=Math.ceil(tc/pageSize);
        if(num==0){
                num=(double) 1;
        }
        pageBean.setTotalPage(num.intValue());
        //封装每页显示的数据
        int begin=(currPage-1)*pageSize;
        List<Admin> list=this.iAdminInfoDao.findAllAdminInfo(begin,pageSize);
        pageBean.setList(list);
        return pageBean;
}

分页查询管理员列表功能: pageBean.setCurrPage(currPage); 封装当前页 int pageSize=3;封装每页记录数 iAdminInfoDao.findAdminCount:封装总记录数 int begin=(currPage-1)*pageSize;int begin=(currPage-1)*pageSize; 首先使用PageBean来做管理员的分页功能,接着记录一下当前页,每页记录数(每页要多少条记录),相乘的话,就是总记录数,最后才是显示数据。

后面的普通用户的分页,商品的分页,类别的分页,都可以使用上面的逻辑。这样就可以抽取出来,成为一个公共方法类。

分类列表查询,用于下列展示

public List<Classify> findAllCateList() {
	List<Classify> cateList=this.iAdminInfoDao.findAllCateList();
	return cateList;
}

通过id查询商品详情

public Product searchProductDetail(int pid) {
	Product product=this.iAdminInfoDao.searchProductDetail(pid);
	return product;
}

通过id删除商品

public void delectProductById(int pid) {
	this.iAdminInfoDao.delectProductById(pid);

}

通过id查询用户详情

public User searchUserDetail(int uid) {
	User u=this.iAdminInfoDao.searchUserDetail(uid);
	return u;
}

通过id删除分类

public void delectCateById(int id) {
	this.iAdminInfoDao.delectCateById(id);

}

通过id删除管理员

public void delectAdminById(int id) {
	this.iAdminInfoDao.delectAdminById(id);

}

新增管理员

public void addAdmin(Admin admin) {
	this.iAdminInfoDao.addAdmin(admin);

}

通过管理员账号查询管理员信息

public Admin findAdminByName(String name) {

	return this.iAdminInfoDao.findAdminByName(name);
}

通过id查询管理员信息

public Admin findAdminById(Integer aid) {

	return this.iAdminInfoDao.findAdminById(aid);
}

修改管理员

public void updateAdmin(Admin admin) {
	this.iAdminInfoDao.updateAdmin(admin);

}

根据分类名称查询分类信息

public Classify findCateByName(String classifyName) {
	Classify c=this.iAdminInfoDao.findCateByName(classifyName);
	return c;
}

新增分类

public void addCate(Classify cassify) {
	this.iAdminInfoDao.addCate(cassify);

}

修改分类

public void updateCate(Classify cassify) {
	this.iAdminInfoDao.updateCate(cassify);

}

后台删除商品发送通知给用户

public void saveSystemMessage(UserAndAdmin uaa) {
	this.iAdminInfoDao.saveSystemMessage(uaa);
        
}

上面是管理员的常用业务代码,增删改查功能,包括管理员,用户,类别以及商品的业务功能。

后面的章节会继续进行拓展,对校园二手商品交易系统常见的功能划分,主要侧重于后端功能,另外也会讲一些主要的前端代码。