<legend id='nLsBk'><style id='nLsBk'><dir id='nLsBk'><q id='nLsBk'></q></dir></style></legend>

<small id='nLsBk'></small><noframes id='nLsBk'>

  1. <i id='nLsBk'><tr id='nLsBk'><dt id='nLsBk'><q id='nLsBk'><span id='nLsBk'><b id='nLsBk'><form id='nLsBk'><ins id='nLsBk'></ins><ul id='nLsBk'></ul><sub id='nLsBk'></sub></form><legend id='nLsBk'></legend><bdo id='nLsBk'><pre id='nLsBk'><center id='nLsBk'></center></pre></bdo></b><th id='nLsBk'></th></span></q></dt></tr></i><div id='nLsBk'><tfoot id='nLsBk'></tfoot><dl id='nLsBk'><fieldset id='nLsBk'></fieldset></dl></div>
        <bdo id='nLsBk'></bdo><ul id='nLsBk'></ul>
      <tfoot id='nLsBk'></tfoot>

      列名作为 Spring Data JPA Query 的参数

      Column name as a parameter to Spring Data JPA Query(列名作为 Spring Data JPA Query 的参数)

            <tbody id='gnstK'></tbody>
          <legend id='gnstK'><style id='gnstK'><dir id='gnstK'><q id='gnstK'></q></dir></style></legend>
              • <bdo id='gnstK'></bdo><ul id='gnstK'></ul>
                <tfoot id='gnstK'></tfoot>

                <small id='gnstK'></small><noframes id='gnstK'>

                <i id='gnstK'><tr id='gnstK'><dt id='gnstK'><q id='gnstK'><span id='gnstK'><b id='gnstK'><form id='gnstK'><ins id='gnstK'></ins><ul id='gnstK'></ul><sub id='gnstK'></sub></form><legend id='gnstK'></legend><bdo id='gnstK'><pre id='gnstK'><center id='gnstK'></center></pre></bdo></b><th id='gnstK'></th></span></q></dt></tr></i><div id='gnstK'><tfoot id='gnstK'></tfoot><dl id='gnstK'><fieldset id='gnstK'></fieldset></dl></div>
                本文介绍了列名作为 Spring Data JPA Query 的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有办法将实体属性动态注入到@Query?我的需要是实现如下方法:

                Is there a way to inject an Entity property dynamically to @Query? My need is to implement a method like follows:

                @Query("select e from #{#entityName} e where e.***columnName*** = ?2")
                List<T> findAll(String ***columnName***, String value);
                

                还有其他简单的方法吗?

                Any other simple ways of doing this?

                推荐答案

                你可以使用 Spring Specification 来实现.

                You can do it using Spring Specification.

                您的规范方法将类似于以下一种:

                Your specification method will be similar to the following one:

                public static Specification<Entity> byColumnNameAndValue(String columnName, String value) {
                    return new Specification<Entity>() {
                        @Override
                        public Predicate toPredicate(Root<Entity> root,
                                CriteriaQuery<?> query, CriteriaBuilder builder) {
                            return builder.equal(root.<String>get(columnName), value);
                        }
                    };
                }
                

                请阅读一下规范,这是一个很棒的工具.

                Please read a little about Specification, it's a great tool.

                https://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/

                http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/domain/Specifications.html

                这篇关于列名作为 Spring Data JPA Query 的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                <tfoot id='5VzDQ'></tfoot>
              • <small id='5VzDQ'></small><noframes id='5VzDQ'>

                • <legend id='5VzDQ'><style id='5VzDQ'><dir id='5VzDQ'><q id='5VzDQ'></q></dir></style></legend>
                    <i id='5VzDQ'><tr id='5VzDQ'><dt id='5VzDQ'><q id='5VzDQ'><span id='5VzDQ'><b id='5VzDQ'><form id='5VzDQ'><ins id='5VzDQ'></ins><ul id='5VzDQ'></ul><sub id='5VzDQ'></sub></form><legend id='5VzDQ'></legend><bdo id='5VzDQ'><pre id='5VzDQ'><center id='5VzDQ'></center></pre></bdo></b><th id='5VzDQ'></th></span></q></dt></tr></i><div id='5VzDQ'><tfoot id='5VzDQ'></tfoot><dl id='5VzDQ'><fieldset id='5VzDQ'></fieldset></dl></div>

                        <bdo id='5VzDQ'></bdo><ul id='5VzDQ'></ul>

                          <tbody id='5VzDQ'></tbody>