Created
June 26, 2016 09:32
-
-
Save mvitz/02b216b0e8a8064ec7af8413d8e5273b to your computer and use it in GitHub Desktop.
Empty query parameters should not be shown in build URI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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...