Skip to content

Instantly share code, notes, and snippets.

@mvitz
Created June 26, 2016 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvitz/02b216b0e8a8064ec7af8413d8e5273b to your computer and use it in GitHub Desktop.
Save mvitz/02b216b0e8a8064ec7af8413d8e5273b to your computer and use it in GitHub Desktop.
Empty query parameters should not be shown in build URI.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
@SpringBootApplication
@Controller
public class MvcUriComponentsBuilderApplication {
public static void main(String[] args) {
SpringApplication.run(MvcUriComponentsBuilderApplication.class, args);
}
@RequestMapping("/")
@ResponseBody
public String index(@RequestParam(value = "q", defaultValue = "") String query, Model m) {
return MvcUriComponentsBuilder.fromMappingName("UBA#index").build();
}
}
@mvitz
Copy link
Author

mvitz commented Jun 26, 2016

I would expect that optional query parameters of a controller method are not rendered in a build URI. However the current implementation renders these parameters without equal sign and value. Normally this isn't a problem but when using such an URI in a GET form this leads to problems...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment