直接放一個(gè)自己用過的例子:
@Override
public List<ShipDto> findShip(String name, String mmsi) {
Ship ship = new Ship();
if(StringUtils.isNotBlank(name)){
ship.setShipFullName(name);
}
if(StringUtils.isNotBlank(mmsi)){
ship.setMmsi(mmsi);
}
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("shipFullName", ExampleMatcher.GenericPropertyMatchers.contains())//模糊查詢匹配開頭蚓炬,即{username}%
.withMatcher("mmsi" ,ExampleMatcher.GenericPropertyMatchers.contains());//全部模糊查詢撩匕,即%{address}%
Example<Ship> example = Example.of(ship ,matcher);
//List<Ship> list = shipDao.findAll(example);
return null;
}