Spring 引导搜索无法正常工作
Spring Boot search is not working properly
这里我想通过 hotel name
检索酒店,但它只返回具有我包含的第一个字母的酒店。
我搜索的酒店名称是“Sigiriya”,但当我输入“s”时,结果是 Sigiriya。但是当我开始输入更多(“igiriya”)时,结果消失了。
/**
*
* @param searchkey
* @return - List of hotels
*/
public List<Hotel> searchHotelByName( String searchkey){
searchkey = searchkey.toLowerCase();
searchkey = "%" + searchkey + "%";
return hotelRepository.findAllByHotelNameContentLike( searchkey );
}
使用 contains
JPA keyword
public List<Hotel> searchHotelByName( String searchkey){
return hotelRepository.findAllByHotelName IgnoreCaseContaining( searchkey );
}
contains
负责 %
等
我认为原因是即使您将搜索关键字转换为小写字母,您的数据库仍包含大写字母。因此使用 ignore case search
.
/**
*
* @param searchkey
* @return - List of hotels
*/
public List<Hotel> searchHotelByName( String searchkey){
searchkey = searchkey.toLowerCase();
return hotelRepository.findAllByHotelNameIgnoreCaseContaining( searchkey );
}
这里我想通过 hotel name
检索酒店,但它只返回具有我包含的第一个字母的酒店。
我搜索的酒店名称是“Sigiriya”,但当我输入“s”时,结果是 Sigiriya。但是当我开始输入更多(“igiriya”)时,结果消失了。
/**
*
* @param searchkey
* @return - List of hotels
*/
public List<Hotel> searchHotelByName( String searchkey){
searchkey = searchkey.toLowerCase();
searchkey = "%" + searchkey + "%";
return hotelRepository.findAllByHotelNameContentLike( searchkey );
}
使用 contains
JPA keyword
public List<Hotel> searchHotelByName( String searchkey){
return hotelRepository.findAllByHotelName IgnoreCaseContaining( searchkey );
}
contains
负责 %
等
我认为原因是即使您将搜索关键字转换为小写字母,您的数据库仍包含大写字母。因此使用 ignore case search
.
/**
*
* @param searchkey
* @return - List of hotels
*/
public List<Hotel> searchHotelByName( String searchkey){
searchkey = searchkey.toLowerCase();
return hotelRepository.findAllByHotelNameIgnoreCaseContaining( searchkey );
}