SQLSERVER using Spring Data JPA fuzzy query like

Mysql can use the function CONCAT

@Query("SELECT u.username FROM User u WHERE u.username LIKE CONCAT('%',:username,'%')")
List<String> findUsersWithPartOfName(@Param("username") String username);

  

SQLSERVER 2008r2 does not support CONCAT function, check a lot of ways to find a final compromise, and that is the% content as a parameter

public interface WpxxRepository extends JpaRepository<Wpxx, Long> {

    @Query(value = " from  Wpxx where wpmc like :mc ")
    List<Wpxx> findAllByName(@Param("mc") String mc);
}

  

WpxxDaoImpl call time
 @Override
    public List<Wpxx> findAllByName(String mc) {
        return wpxxRepository.findAllByName("%"+mc+"%");
    }

  If you want to query like '% test%', calls WpxxDaoImpl method findAllByName ( "test"), passed in time to WpxxRepository is findAllByName ( "% test%")

Guess you like

Origin www.cnblogs.com/zyh1989/p/10942927.html