Spring 数据休息按关键字搜索
Spring Data Rest search by keyword
我正在寻找实现关键字搜索的解决方案。最终 API 应该看起来像 /persons/search?keyword=test
。搜索应该检查几列人员 table (firstName, lastName, school, ...)
。
在结果列表中,我需要至少在一列中包含关键字的人员列表。
使用 Spring Data Rest 实现该目标的最佳解决方案是什么?
在存储库上使用 @Query
注释,您可以这样做:
public interface PersonRepository extends CrudRepository<Persons, Long> {
@Query("SELECT p FROM Persons where LOWER(p.firstname) like :key%"
+ " or LOWER(p.lastname) like :key%" )
public List<Person> searchBy(@Param("word") String key);
}
注意:我做了类似的事情,但我现在没有确切的代码,所以只需检查语法,但我能用这个实现什么是能够使用单个键搜索多个列。
我正在寻找实现关键字搜索的解决方案。最终 API 应该看起来像 /persons/search?keyword=test
。搜索应该检查几列人员 table (firstName, lastName, school, ...)
。
在结果列表中,我需要至少在一列中包含关键字的人员列表。
使用 Spring Data Rest 实现该目标的最佳解决方案是什么?
在存储库上使用 @Query
注释,您可以这样做:
public interface PersonRepository extends CrudRepository<Persons, Long> {
@Query("SELECT p FROM Persons where LOWER(p.firstname) like :key%"
+ " or LOWER(p.lastname) like :key%" )
public List<Person> searchBy(@Param("word") String key);
}
注意:我做了类似的事情,但我现在没有确切的代码,所以只需检查语法,但我能用这个实现什么是能够使用单个键搜索多个列。