另一点。如何创建这样的复杂查询?
SELECT businesscentr.email
FROM businesscentr, banners, businessbanner, click
WHERE click.id_banner = banners.id_banner AND banners.id_banner = businessbanner.id_banner AND businessbanner.id_bc = businesscentr.id_bc
存储库扩展JpaRepository<Click, Long>
。
@Query("select c from Click c where c.id_bannners = :idbanners and c.fullname_client = :fullnameClient")
String sent(@Param("fullname_client") String fullnameClient, @Param("id_banner") long idbanners);
错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clickController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.qoobico.remindme.server.service.ClickService com.qoobico.remindme.server.controller.ClickController.service; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clickServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.qoobico.remindme.server.repository.ClickRepository com.qoobico.remindme.server.service.ClickServiceImpl.clickRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clickRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Using named parameters for method public abstract java.lang.String com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long) but parameter 'fullname_client' not found in annotated query 'select c from Click c where c.id_bannners = :idbanners and c.fullname_client = :fullnameClient'!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at
答案 0 :(得分:1)
问题是您的参数名称与查询参数名称
不匹配你有
@Query("select c from Click c where c.id_bannners = :idbanners and c.fullname_client = :fullnameClient")
String sent(@Param("fullname_client") String fullnameClient, @Param("id_banner") long idbanners);
你应该
@Query("select c from Click c where c.id_bannners = :id_banner and c.fullname_client = :fullname_client")
String sent(@Param("fullname_client") String fullnameClient, @Param("id_banner") long idbanners);
参数和查询如何在彼此之间匹配