如何在@Query 中使用枚举作为常量 [英] How to use enum in @Query as a constant
本文介绍了如何在@Query 中使用枚举作为常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 !=
之后放置一个完整的类路径 (com.xxxx.State.Finish),但没有帮助.
I have tried to put a full class path (com.xxxx.State.Finish) after !=
but not helping.
@Query("select c from CustomOrder c where c.dealer = :roleName and
c.nextManager = null and c.currentState != Finish")
List<CustomOrder> findOpenOrder(@Param("roleName") String roleName);
实体:
@Getter
@Enumerated(EnumType.STRING)
CustomOrderEnums.State currentState;
枚举:
public enum State {
Open, Finish
}
推荐答案
@Query("select c from CustomOrder c where c.dealer = :roleName and
c.nextManager = null and c.currentState != com.xxx.FooEnum.Finish")
FooEnum
必须是顶级而不是内部.如果必须是内部类,使用'
引用字符串(没有'
的没试过).
FooEnum
has to be a top class not an inner one. If it has to be an inner class, use '
quoted string (haven't tried it without '
).
@Query("select c from CustomOrder c where c.dealer = :roleName and
c.nextManager = null and c.currentState != 'Finish'")
我刚刚发现,除了使用 @Query
它可以简单地用作:
I have just found that instead of using @Query
it could be simply used as:
List<User> findIdByRoleRoleAndProvinceType(String role, ProvinceEnum.ProvinceType provinceType);
这是实体用户:
@Entity
public class User {
Role role; // entity has a String field role;
Province province; // entity has a ProvinceEnum.ProvinceType field type.
...
}
这篇关于如何在@Query 中使用枚举作为常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文