Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-490

Add support for optional query method parameters.

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Repositories
    • Labels:
      None

      Description

      The use of Optional as method parameter type or @Param(optional=true) would potentially allow to create conditional query parts that only make their way into the final query in case a value is set.

      List<Entity> findByNameOrDescription(@Param(optional=true) String name, Optional<String> description);
      
      //---
      
      //SELECT * FROM Entity WHERE name = 'foo' AND description = 'bar'
      findByNameOrDescription("foo", Optional.of("bar"));
      
      //SELECT * FROM Entity WHERE name = 'foo'
      findByNameOrDescription("foo", Optional.empty());
      
      //SELECT * FROM Entity WHERE description = 'bar'
      findByNameOrDescription(null, Optional.of("bar"));
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              cstrobl Christoph Strobl
              Reporter:
              cstrobl Christoph Strobl
              Last updater:
              Spring Issues Spring Issues
              Votes:
              4 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: