这是我的存储库
public interface NoteRepository extends JpaRepository<Note,Long> {
List<Note> findByContentContains(String content);
以及我在类 NoteController 中的方法,它返回内容列中带有“e”的单词
@GetMapping("/notesletter")
public List<String> getLetters(){
return noteRepository.findByContentContains("e")
.stream()
.map(note -> note.getContent())
.collect(Collectors.toList());
}
请帮助我找到一种方法,该方法可以返回所有列中的每个带有字母“e”的单词。 我正在与 postman 合作
最佳答案
当然你可以进行原生查询
@Query("select u from Note u where u.COL1 = ?1 and u.COL2 = ?1")
List<Note> findByContentContains(String content)
或者使用下面给出的jpa功能,注意提到findByLastnameOrFirstnameStartingWith是为了容易理解,所以分别将你的名字,姓氏替换为colu1name,col2name。 Refer here for more jpa method conventions `
public interface NoteRepository extends JpaRepository<Note,Long> {
List<Note> findByLastnameOrFirstnameStartingWith(String param1,String param2)
static List<Note> findByContentContains(String content){
findByLastnameOrFirstnameStartingWith(content,content);
}
}
关于java - 如何使用 Spring Data JpaRepository 在所有列中查找字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48586157/