1.首先我的Dao层注入成功,已经测试成功,但是Controller成注入Service时,发现注入的Service为空。
2.配置文件
其余配置文件为Dao层数据库相关,以及sql映射文件的配置,就不写了
测试类
@Autowired
BrandDao brandDao;
BrandService brandService;
@Test
public void test3() throws Exception{
Brand brand = new Brand();
brand.setIsDisplay(1);
//当前页码(如果当前页码小于1或者为空时,将其置为1)
brand.setPageNo(1);
System.out.println(brandService);
Pagination pagination=brandService.getBrandListWithPage(brand);
}
}
Service实现类
@Service
@Transactional
public class BrandServiceImpl {
@Autowired
BrandDao brandDao;
@Transactional(readOnly = true)
public Pagination getBrandListWithPage(Brand brand) {
/*
* @pageNo:当前页码
*
* @pageSize:每页的记录数
*
* @totalCount:总记录数
*/
System.out.println(brandDao);
System.out.println(brandDao.getBrandCount(brand));
int pageNo=brand.getPageNo();
Pagination pagination=new Pagination(Pagination.cpn(pageNo), 5, brandDao.getBrandCount(brand));
pagination.setList(brandDao.getBrandListWithPage(brand));
return pagination;
}
}
你的service中有没有添加@Service或者@Component注解呀