也许由于我的实体有关系而在
@Query
中出错?
存储库包含错误。
创建名为“clickRepository”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IllegalArgumentException: 查询方法 public abstract 的验证失败 java.lang.字符串 com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)!
控制器
@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: 错误 创建名称为“clickController”的 bean:注入自动装配 依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法 自动装配字段:私有 com.qoobico.remindme.server.service.ClickService com.qoobico.remindme.server.controller.ClickController.service;嵌套 例外是 org.springframework.beans.factory.BeanCreationException: 创建名为“clickServiceImpl”的 bean 时出错:注入 自动装配依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法 自动装配字段:私有 com.qoobico.remindme.server.repository.ClickRepository com.qoobico.remindme.server.service.ClickServiceImpl.clickRepository; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建名为“clickRepository”的 bean:调用 init 方法 失败的;嵌套异常是 java.lang.IllegalArgumentException: 查询方法 public abstract 的验证失败 java.lang.字符串 com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)!
您的参数名称不同。试试这个:
@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.