Parameter in like clause JPQL

后端 未结 8 1357
盖世英雄少女心
盖世英雄少女心 2020-11-27 03:20

I am trying to write a JPQL query with a like clause:

LIKE \'%:code%\'

I would like to have code=4 and find

455
554
646
...
         


        
8条回答
  •  天命终不由人
    2020-11-27 03:54

    Use JpaRepository or CrudRepository as repository interface:

    @Repository
    public interface CustomerRepository extends JpaRepository {
    
        @Query("SELECT t from Customer t where LOWER(t.name) LIKE %:name%")
        public List findByName(@Param("name") String name);
    
    }
    
    
    @Service(value="customerService")
    public class CustomerServiceImpl implements CustomerService {
    
        private CustomerRepository customerRepository;
        
        //...
    
        @Override
        public List pattern(String text) throws Exception {
            return customerRepository.findByName(text.toLowerCase());
        }
    }
    

提交回复
热议问题