在我的 Spring Boot 应用程序中,我尝试使用 DTO 实现基于类的投影,如下所述:
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections.dtos
我有一个域类,如下所示:
@Entity
@Table(name="metadatavalue")
public class MetadataValue {
@Id
@Column(name="metadata_value_id")
private Integer metadataValueId;
@Column(name="resource_id", insertable=false, updatable=false)
private Integer resourceId;
@Column(name="metadata_field_id", insertable=false, updatable=false)
private Integer metadataFieldId;
@Column(name="text_value")
private String textValue;
Run Code Online (Sandbox Code Playgroud)
接下来是更多的类成员、getter 和 setter 等。
我还有一个简单的 DTO 类,其中有一名成员:
public class MetadataDTO {
private String textValue;
public MetadataDTO(String textValue) {
this.textValue = textValue;
}
public String getTextValue() {
return textValue;
}
}
Run Code Online (Sandbox Code Playgroud)
我的存储库类是:
public interface MetadataValueRepository extends CrudRepository<MetadataValue, Integer> {
@Query("SELECT m from MetadataValue m WHERE m.handle.handle …Run Code Online (Sandbox Code Playgroud)