带有自定义类 Spring Boot Java 的 @Query 注释 [英] @Query annotation with custom Class Spring Boot Java

查看:45
本文介绍了带有自定义类 Spring Boot Java 的 @Query 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JPA 用户的问题,以下是否可能?

question for JPA-Users, is the following somehow possible?

@Query(value = "SELECT * FROM Users u WHERE u.status = :sampleClass.status", 
  nativeQuery = true)
List<SampleClass> findBySampleClass(SampleClass sampleClass);

注意我试图访问 @Query 注释中的 SampleClass 的方式.无法做到这一点,而是选择了 Criteria 并构建了我的老式查询.

Notice the way I am trying to access SampleClass in the @Query annotation. Wasn't able to get this going, instead went for Criteria and constructed my query old-school.

推荐答案

您可以使用 JPA 文档中提到的方法:

You could use the approach as mentioned in the JPA docs:

    @Query(value = "SELECT * FROM Users u WHERE u.status = ?1",
 nativeQuery = true)
    List<SampleClass> findBySampleClass(String status);

更多选项请参考官方文档:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#_native_queries

Please refer to the official docs for further options : https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#_native_queries

不知道你为什么要尝试传递整个对象.你愿意解释一下吗?

Not sure why you are trying to pass the whole object though.Would you care to explain?

这篇关于带有自定义类 Spring Boot Java 的 @Query 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆