【发布时间】:2019-12-18 11:11:11
【问题描述】:
我尝试使用 all(array[]) 函数使用 Spring Boot 进行本机查询,但是我无法正确完成。我不知道要传递的字符串数量,它是一个动态数量。请问各位大神能帮帮我吗?
我尝试过使用List<String>、String[] 和String,如下所示:
通过
String并在查询all(array[:texto])中:没有错误,但是没有结果。传递
List<String>并在查询中all(array[:texto]):
org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying ~~* record
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
- 传递
String[]并在查询中all(array[:texto]):
org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying ~~* bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
- 通过
String[]并在查询all(array[CAST(:texto AS TEXT)])中:没有错误,但是没有结果。
@Query(value="SELECT * FROM Tag WHERE nome ILIKE all(array[:texto])", nativeQuery=true)
public List<Tag> findPacotesByTexto(@Param("texto") List<String> texto);
已编辑:
@Entity
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)
private String nome;
@ManyToOne
@JsonIgnore
@JoinColumn(name="pacote_id")
private Pacote pacote;
Tag() {
}
public Tag (String nome, Pacote pacote) {
this.nome = nome;
this.pacote = pacote;
}
public long getId() {
return id;
}
public String getNome() {
return nome;
}
public Pacote getPacote() {
return pacote;
}
}
我怎样才能做到这一点?
提前致谢。
【问题讨论】:
-
也分享
Tag,以防万一。 -
我已经添加了,谢谢
标签: java postgresql spring-boot jpa