java - 如何在Spring Boot中默认阻止@PathVariable值的解码

标签 java spring-boot

我有一个在 Tomcat 上运行的 Spring-Boot 应用程序。在其中,我有一个带有路径变量的 RestController 。 默认情况下,路径变量会被解码,例如如果我给出 http://localhost:8080/v1/test/test2/%26 ,路径变量自动解码为 & ,我需要禁用此自动解码。


@RequestMapping(value = "/v1/test/test2//{pathVariable:.+}", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
     public String getV2LocationByName(
                                      @PathVariable
                                      String cityName,
                                      @RequestParam(value = LANGUAGE, defaultValue = US_ENGLISH_LOCALE) String language,
                                      HttpServletRequest request) throws InterruptedException, ExecutionException {
--------------
---------------
}

最佳答案

也许尝试用 UTF-8 对其进行编码

String encodedParam = URLEncoder.encode(test, "UTF-8");

您可以找到更多详细信息here

关于java - 如何在Spring Boot中默认阻止@PathVariable值的解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55613904/

相关文章:

java - LibGDX:似乎无法绘制数组中的对象

java - 发现多个文件的操作系统独立路径为 'android/databinding/DataBindingComponent.java'

java - 两个类具有相同的 XML 类型名称 "objectFactory"

java - Thymeleaf + Spring Boot : Error resolving template

Spring Boot 和 Hibernate 延迟初始化的奇怪行为

java - 准备响应主体的逻辑应该在@Service还是@Controller上?

javascript - 从 javascript 文件中提取信息到远程站点

java - 将元数据添加到 Java RMI

Java - 日期、格式、时区和 Spring Boot 默认值

java - Spring AOP - 如果没有 xml 配置,方面就无法工作