gpt4 book ai didi

spring - 将实体链接作为@RequestParam 传递给@RepositoryRestController 方法

转载 作者:行者123 更新时间:2023-12-04 19:46:23 27 4
gpt4 key购买 nike

我里面有一个 @RepositoryRestController

@RequestMapping(value = "/products/salesReport", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody
ResponseEntity<?> get(
@RequestParam(value = "customer", required = false) Resource<Organization> customer,
@RequestParam(value = "supplier", required = false) Organization supplier,
@DateTimeFormat(pattern = "dd-MM-yyyyy") @RequestParam(value = "startDate", required = false) Date startDate,
@DateTimeFormat(pattern = "dd-MM-yyyyy") @RequestParam(value = "endDate", required = false) Date endDate,
Pageable pageable
) { ...

这里的组织类型请求参数,我想作为 SDR 样式的 uris 传入。当我传入 Long ids 时,它工作正常并自动转换为实体对象。但是当我传入 uri 时,我得到:
Failed to convert value of type [java.lang.String] to required type [org.springframework.hateoas.Resource]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.hateoas.Resource]: no matching editors or conversion strategy found"

有谁知道 Spring 是否真的支持在 @RepositoryRestController 中自动将 uri 转换为实体对象如何?

最佳答案

试试这个方法:

@RepositoryRestController
@RequestMapping("/products")
public class ProductsController {

@Autoware
private ProductService productService;

@GetMapping("/{id}/report/{data}")
public ResponseEntity<?> getReport(@PathVariable("id") Product product, @PathVariable("date") Date date) {
// some checks...
return ResponseEntity.ok(productService.makeReport(product, date);
}
}

关于spring - 将实体链接作为@RequestParam 传递给@RepositoryRestController 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45101623/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com