【发布时间】:2019-04-05 23:07:15
【问题描述】:
我有一个带有 JPA 的 Spring Boot 应用程序。 我需要将查询中的值映射到实体。
示例实体
@Entity
@Table(name = "questions")
@DynamicUpdate
public class Question{
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Lob
private String description;
@Transient
private int noOfViews;
}
示例查询
@Repository
public interface QuestionRepository extends JpaRepository<Question, Long> {
@Query(value = "select q.*, 2 NO_OF_VIEWS from questions q
order by q.id DESC ", countQuery = "select count(*) from questions q order by q.id DESC " ,nativeQuery = true)
Page<Question> findQuestions(Pageable pageable);
}
我需要将值设置为 noOfViews 字段。对此有任何想法吗? Spring 有 RowMapper 接口,但没有找到任何用于 spring boot 的东西。
【问题讨论】:
标签: sql spring-boot jpa spring-data-jpa