<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 的参数

      时间:2024-08-24

            <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 的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:选择特定列的 Spring Data JPA 规范 下一篇:spring jpa @Query 错误,期待 CLOSE,发现 '(' 附近

                相关文章

                <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>