title: What Should Sorting In My Controller Look Like?
body: <p>I have a Spring controller for my REST API that currently allows searching by various parameters:</p>
  <pre><code>@GetMapping(value = &quot;/dogs&quot;, produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity&lt;ResponseDTO&lt;DogDTO&gt;&gt; getDogs(
    @RequestParam(defaultValue = &quot;1&quot;) Integer page,
    @RequestParam(defaultValue = &quot;10&quot;) Integer size,
    @RequestParam(required = false) String colour,
    @RequestParam(required = false) String breed,
    @RequestParam(required = false) String name,
  </code></pre>
  <p>e.g. <code>/api/dogs?colour=black&amp;breed=labrador</code></p>
  <p>The response is currently displayed in a table but now there is a requirement to search asc or desc on any of these columns - but not on more than one at the same time.</p>
  <p>How should I change my controller definition to add sorting on these parameters and specify asc and dec?<br />
  and what would the url look like after these changes?</p>
  <p>e.g.</p>
  <pre><code>/api/dogs?colour=black?sort=-id
  /api/dogs?colour=black?sort=id&amp;dir=asc
  </code></pre>