Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Springboot中的Trim@RequestParam_Java_Spring_Spring Boot - Fatal编程技术网

Java Springboot中的Trim@RequestParam

Java Springboot中的Trim@RequestParam,java,spring,spring-boot,Java,Spring,Spring Boot,有没有办法在springboot中修剪@RequestParam。 例如: @RestController public class Controller{ @GetMapping(value = "/v1/test/", produces = "application/json") public Response getTest( @RequestParam(name = "name") String name){ } } 根据我的理解,您需要获得输出,即使它包含空格 G

有没有办法在springboot中修剪
@RequestParam
。 例如:

@RestController
public class Controller{
  @GetMapping(value = "/v1/test/", produces = "application/json")
  public Response getTest(
    @RequestParam(name = "name") String name){
  }
}

根据我的理解,您需要获得输出,即使它包含空格

GET: localhost:8080/v1/test/?name =test
GET: localhost:8080/v1/test/?name=test
所以我建议你可以用“Map”代替字符串。 下面的代码是我的示例代码,您可以参考它并相应地使用

@RequestMapping("/api")
public class DemoController {
    
    @GetMapping("/person/id")
    private String getStudent(@RequestParam Map<String,String> name) throws Exception {
        String value = null;
        if((name.get("g") !=null) || (name.get("g ")) !=null) 
        {
            value = "even";
        }
        else {
            value ="odd";
        }
        return value;
    }
}
@RequestMapping(“/api”)
公共类DemoController{
@GetMapping(“/person/id”)
私有字符串getStudent(@RequestParam映射名)引发异常{
字符串值=null;
if((name.get(“g”)!=null)|(name.get(“g”)!=null)
{
value=“偶数”;
}
否则{
value=“奇数”;
}
返回值;
}
}
改变将是
@RequestParam映射名
-我已更改 并引入了一个条件来检查
是否((name.get(“g”)!=null)|(name.get(“g”)!=null)


谢谢:)

这可能有助于检索所有参数,然后进行微调:因此,例如,如果用户尝试
localhost:8080/v1/test/?name=test
,它应该微调“name”=>“name”
@RequestMapping("/api")
public class DemoController {
    
    @GetMapping("/person/id")
    private String getStudent(@RequestParam Map<String,String> name) throws Exception {
        String value = null;
        if((name.get("g") !=null) || (name.get("g ")) !=null) 
        {
            value = "even";
        }
        else {
            value ="odd";
        }
        return value;
    }
}