Java Springboot中的Trim@RequestParam
有没有办法在springboot中修剪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
@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;
}
}