SpringBoot解析URI查询

时间:2018-05-09 15:27:37

标签: java spring-boot

我写了一个课,我尝试发送一个请求: 网址:http://localhost:8080/?Name=%F8%FA

但是我收到了错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.eclipse.jetty.http.BadMessageException: 400: Unable to parse URI query

代码:

@RestController
@EnableAutoConfiguration
public class DemoApplication {

@RequestMapping(value = "/*",
                method = RequestMethod.GET)

public String getName(
        @RequestParam(name = "Name", required = false) String name
 ) {
    return name;
}

public static void main(String[] args) throws Exception {
    SpringApplication.run(DemoApplication.class, args);
    }

}

1 个答案:

答案 0 :(得分:0)

这是我尝试的代码,它正在运行

Spring boot主类:

@SpringBootApplication
public class TestApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);         
    }
}

控制器代码:

@RestController
public class TestController {


    @RequestMapping(value = "/*", method = RequestMethod.GET)
    public String getName(@RequestParam(name = "Name", required = false) String name) {
        return name;
    }
}