java - Lors de l'écriture d'une pagination dans le framework SSH, la classe de pagination ne peut pas être injectée dans la couche de service
阿神
阿神 2017-06-12 09:24:51
0
3
825

couche de service

@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;
    }

couche d'action

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)}


Si au lieu d’utiliser l’injection, il suffit d’utiliser la nouvelle méthode, pourquoi ?

阿神
阿神

闭关修行中......

répondre à tous(3)
世界只因有你

La classe

PageUntil doit également utiliser @Component

黄舟

Vous n'avez pas utilisé @Resource correctement, ce qui a entraîné l'absence du <bean> avec l'attribut de nom "iauthoradmindao" dans le fichier de configuration, vous pouvez donc essayer de remplacer @Resource par @AutoWired. Les méthodes d'injection de ces deux annotations sont différentes. Bien entendu, le principe est que votre fichier XML doit être équipé d'un <bean>

de type "IAuthorAdminDao".

Pour plus de détails, veuillez vous référer à : https://www.zhihu.com/questio...

phpcn_u1582

Je pense qu’il est plus facile d’utiliser du nouveau. Votre classe doit-elle réfléchir à des questions particulières ?

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!