当前位置: 首页 > 知识库问答 >
问题:

@query,Repository中出错

包兴思
2023-03-14
 @Autowired
private ClickService service;

/*
    i.e. information about fullname_client, id_banner sent to server from client
*/
@RequestMapping(value = "/sentemail", method = RequestMethod.POST)
@ResponseBody
public String sentClick(@RequestParam ("fullnameClient") String fullnameClient,@RequestParam ("idbanners") long idbanners) {

    return service.sent(fullnameClient, idbanners);
}
@Query("SELECT c.fullnameClient FROM Click AS c join c.idBanner Banners b WHERE b.idBanner = :idbanners AND c.fullnameClient = :fullnameClient")
String sent(@Param("fullnameClient") String fullnameClient, @Param("idbanners") long idbanners);
@Id
@Column(name = "id_click", unique = true, nullable = false)
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private long idClick;

@ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@JoinColumn(name = "id_banners", nullable = false)
private Banners idbanners;

@Column(name = "fullname_client", nullable = false, length = 50)
private String fullnameClient;
@Id
@Column(name = "id_banner", unique = true, nullable = false)
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private long idBanner;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "banners")
private Set<Businessbanner> businessbanners;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "idbanners")
private Set<Click> clicks;

错误

org.springframework.beans.factory.BeanCreationException:创建名为“Click Controller”的bean时出错:注入autowired依赖项失败;嵌套异常为org.springframework.beans.factory.beancreationexception:无法自动连接字段:private com.qoobico.remindme.server.service.clickservice com.qoobico.remindme.server.controller.clickcontroller.service;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“Click ServiceImpl”的bean时出错:注入autowired依赖项失败;嵌套异常为org.springframework.beans.factory.beancreationexception:无法自动连接字段:private com.qoobico.remendme.server.repository.clickrepository com.qoobico.remendme.server.service.clickserviceimpl.clickrepository;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“click repository”的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:方法public abstract java.lang.String com.qoobico.remindme.server.Repository.ClickRepository.Sent(java.lang.String,long)查询验证失败!

共有1个答案

龙洛城
2023-03-14

您的参数名称不同。试试看:

 @Query("SELECT c.fullnameClient FROM Click AS c join c.idbanners b WHERE b.idBanner = :idbanners AND c.fullnameClient = :fullnameClient")

    String sent(@Param("fullnameClient") String fullnameClient, @Param("idbanners ") long idbanners);

更新

好的,你的加入是错误的…而不是c加入c.idBanner。应该是c.idbanners。

 类似资料:
  • 我正在通过Spring data JPA中的CrudRepository检索数据。我想过滤从注释中提供的自定义查询中检索到的记录。我尝试了用于但它会给出错误。我想筛选表中的前20行 这是我的存储库 我想要我的

  • 是否有可能以更优雅的方式实现此功能?Spring数据在这种情况下提供任何支持吗?

  • Laravel Repositories Laravel Repositories is a package for Laravel 5 which is used to abstract the database layer. This makes applications much easier to maintain. Installation Run the following comma

  • 是否可以在Spring Repository@Query注释中使用Array对象作为参数? 我正在尝试检索列节点存在于字符串数组中的表中的所有行。是否可以使用Spring存储库中的@Query注释一次执行此操作? 这是我的位置实体: 其中node引用node类,它在数据库中作为BIGINT映射。 我有这样一个存储库: 在那里,您可以看到我试图执行的查询,但它不起作用。我不知道是否可以在那里使用数组

  • Table of Contents Setting up the repository indexer Gitea can search through the files of the repositories by enabling this function in your app.ini: [indexer] ; ... REPO_INDEXER_ENABLED = true REPO_I