sql - 在本机查询中映射 JPA 中的值
问题描述
我有一个带有 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 的东西。
解决方案
推荐阅读
- javascript - 如何在烧瓶网络服务器上检索数据作为文件对象?
- scala - 比较字符串时,如果语句在 scala 中永远不会返回 true
- ionic-framework - 从 Ionic 4 / Angular 7 升级到带有 Angular 9 的 Ionic 5
- flutter - 颤振:我无法保持用户登录
- javascript - Javascript 范围 - onchange 事件
- excel - 使用宏获取网站下拉列表的完整数据
- node.js - 连接到 SQL Server 时出现证书错误
- reactjs - 如何处理 React axios 如何处理 net::ERR_CONNECTION_REFUSED
- python - Python中二维矩阵的傅里叶变换
- flutter - Flutter:升级到新应用版本后显示更改日志/发布说明/“新增功能”