JpaRepository和CrudRepository错误 [英] JpaRepository and CrudRepository error
问题描述
为什么会出现这样的错误?
我使用的是Spring Data JPA 1.3.3,Spring 4.2.8和Spring MVC 4.2.8。
Why happen such error? I am using Spring Data JPA 1.3.3 , Spring 4.2.8 and Spring MVC 4.2.8.
更新:
代码块错误
UPDATE: Error as code block
错误:错误:行(8)java:名称冲突:在org.springframework.data.jpa中保存(java.lang.Iterable)。 org.springframework.data.repository.CrudRepository中的repository.JpaRepository和save(java.lang.Iterable)具有相同的擦除,但都不会覆盖其他
Error:Error:line (8)java: name clash: save(java.lang.Iterable) in org.springframework.data.jpa.repository.JpaRepository and save(java.lang.Iterable) in org.springframework.data.repository.CrudRepository have the same erasure, yet neither overrides the other
我的所有库都添加为IntelliJ Idea的模块。 Maven只下载了JSTL。
All my libraries added as IntelliJ Idea's Module. Only JSTL is downloaded by Maven.
推荐答案
对于spring数据jpa,在repo中编写本机查询并不是一个好主意。除非您的要求只是难以编写查询方法。
For spring data jpa, It's not really good idea to write native query in repo. Unless your demands are just to hard to write query methods.
对于您的情况,您只需要这样的简单查询方法
For your case, you just need simple query methods like this
List<User> findByFirstName(String firstName);
返回用户列表,因为许多用户可能拥有相同的用户名
Return list of User because many Users might have the same userName
看一下spring data doc 查询方法
Take a look at spring data doc Query methods
希望它有所帮助:)
这篇关于JpaRepository和CrudRepository错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!