我目前正在编写一个springbootsrestapi,并希望对在 GetMapping
. 在djangoweb框架中,有一种方法可以做到这一点:反向。但我找不到类似的春靴。
我在找这样的东西:
package help.me.stack.overflow;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("api")
public class SomeController {
@GetMapping(value = "/items/{filter}/blob")
public ResponseEntity<?> getItems(@PathVariable String filter, @RequestParam String sorting) {
return ResponseEntity.ok().body("here you go");
}
@GetMapping(value = "/give-me-url")
public ResponseEntity<?> getTheUrl() {
return resolveUrl(SomeController.getItems, "foo-filter", "foo-sorting");
// should produce "api/items/foo-filter/blob?sorting=foo-sorting"
}
}
这样的事存在吗?我怎么用?
1条答案
按热度按时间qf9go6mv1#
是的,你可以用
WebMvcLinkBuilder.linkTo(...)
来自spring hateoas:更多示例请参见此处