如何将方法放入@query

rdrgkggo  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(194)

有典型的jpa接口

public interface AnswerPollsRepository extends JpaRepository<EAnswerPoll, Long>{

default String getQuery(Map<String,String>map,Long pollId){
    String sql="select a.* from answer_poll a where a.poll_id ="+pollId;
  return sql+map.entrySet().stream()
        .filter(x->!x.getKey().equals("mail")&&x.getKey().equals("name"))
        .map(x->"and a.parameters->>"+x.getKey()+" like "+x.getValue())
      .collect(Collectors.joining(" "));

 @Query( value = "#{@.getQuery(#id,#map)}" ,nativeQuery = true)
  List<Long>findAllByCustomFilter(@Param("id") Long pollId,@Param("map") Map<String,String>map);

如何将getquery放到@query?或者这是不可能的?这行不通

@Query( value = "#{@.getQuery(#id,#map)}" ,nativeQuery = true)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题