1.方式一:controller层处理
public interface MyRepository extends Repository<TestPerson,Integer> {
Slice<TestPerson> findAllByNameLike(String name,Pageable pageable);
List<TestPerson> findByName(String name);
}
要实现模糊查询需要自己对传参做处理:"%"+参数+"%"
若不做以上处理默认是精确查询
Controller层:
@RequestMapping(value="/test88")
@ResponseBody
public void test88(String name){
Pageable pageable1=PageRequest.of(1,4);
//模糊查询需要特殊做处理
Slice<TestPerson> sss=myRepository.findAllByNameLike("%"+name+"%",pageable);
System.out.println("===");
}
2.SpringData自动处理,不用like,用Containing替代
public interface MyRepository extends Repository<TestPerson,Integer> {
Slice<TestPerson> findAllByNameContaining(String name,Pageable pageable);
}
这样就不用自己添加"%"做模糊查询了