Rumah  >  Soal Jawab  >  teks badan

java - Apabila menulis paging dalam rangka kerja SSH, kelas paging tidak boleh disuntik ke dalam lapisan perkhidmatan

lapisan servis

@Service
public class AuthorAdminServiceImpl implements IAuthorAdminService {
    @Resource
    private IAuthorAdminDao iauthoradmindao;
    @Resource
    PageUntil<AuthorAdmin> pageUntil;
@Override
    public PageUntil<AuthorAdmin> findByPage(int currentPage) {
        pageUntil.setCurrentPage(currentPage);// 当前多少页
        int pageSize = 3;
        pageUntil.setPagesize(pageSize);// 最多显示多少记录
        int totalCount = iauthoradmindao.findCount();// 数据库中所有的记录
        pageUntil.setTotalCount(totalCount);
        double tc = totalCount;
        Double num = Math.ceil(tc / pageSize);// 页面显示的总页数=数据库的总记录数/最多显示多少记录
        pageUntil.setTotalPage(num.intValue());
        int begin = (currentPage - 1) * pageSize;// 当前页开头位置的索引
        List<AuthorAdmin> list = iauthoradmindao.findByPage(begin, pageSize);
        if(list==null){
            System.out.println("list findByPage service error");}
        pageUntil.setList(list);
        
        return  pageUntil;
    }

lapisan tindakan

public String listAuthorAdmin() {
        PageUntil<AuthorAdmin> pageuntil = iauthoradminservice
                .findByPage(currentPage);
        ActionContext.getContext().getValueStack().push(pageuntil);
        return "listSuccess";
    }

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorAdminAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorAdminServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.lcy.until.PageUntil com.lcy.service.author.admin.AuthorAdminServiceImpl.pageUntil; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


----------
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorAdminServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.lcy.until.PageUntil com.lcy.service.author.admin.AuthorAdminServiceImpl.pageUntil; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


----------
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.lcy.until.PageUntil com.lcy.service.author.admin.AuthorAdminServiceImpl.pageUntil; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


----------
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


Sekiranya daripada menggunakan suntikan, cukup dengan menggunakan kaedah baru, kenapa?

阿神阿神2686 hari yang lalu835

membalas semua(3)saya akan balas

  • 世界只因有你

    世界只因有你2017-06-12 09:26:51

    PageUntil kelas pun perlu guna @Component

    balas
    0
  • 黄舟

    黄舟2017-06-12 09:26:51

    Anda tidak menggunakan @Resource dengan betul, menyebabkan <bean> dengan atribut nama "iaauthoradmindao" tidak ditemui dalam fail konfigurasi, jadi suntikan gagal! Kaedah suntikan kedua-dua anotasi ini berbeza Sudah tentu, premisnya ialah fail xml anda mesti dilengkapi dengan <bean>

    jenis "IAuthorAdminDao"

    Untuk butiran, sila rujuk: https://www.zhihu.com/questio...

    balas
    0
  • phpcn_u1582

    phpcn_u15822017-06-12 09:26:51

    Saya rasa ia paling mudah untuk menggunakan baharu. Adakah kelas anda perlu mempertimbangkan isu khas?

    balas
    0
  • Batalbalas