@RequestParam删除URL中的问号

时间:2021-01-25 22:25:04

I am trying to build a REST API with Spring.

我正在尝试使用Spring构建REST API。

How I can replace the URI

我如何替换URI

localhost: 8080 / rest / api / v1 / users / id ?id = 1

by

localhost: 8080 / rest / api / v1 / users / id / 1

1 个解决方案

#1


I succeeded in solve the problem using @PathVariable , example :

我成功地使用@PathVariable来解决问题,例如:

public ResponseEntity<String> hello (@PathVariable Integer id) {

        String hello  ="hello "+ id ;
        return new ResponseEntity<String>(hello, HttpStatus.ACCEPTED);
    }

and the corresponding URL is:

相应的URL是:

localhost:8080/hello/15

Tkx

#1


I succeeded in solve the problem using @PathVariable , example :

我成功地使用@PathVariable来解决问题,例如:

public ResponseEntity<String> hello (@PathVariable Integer id) {

        String hello  ="hello "+ id ;
        return new ResponseEntity<String>(hello, HttpStatus.ACCEPTED);
    }

and the corresponding URL is:

相应的URL是:

localhost:8080/hello/15

Tkx