还有一点。如何创建这样的复杂查询?

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

最佳答案

问题是您的参数名称与查询参数名称不匹配

你有

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


这就是参数和查询彼此匹配的方式

关于java - 单击带有红色下划线的@ Query,JpaRepository,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41855620/

10-12 00:24