我在@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是否支持自动将uris转换为@RepositoryRestController
中的实体对象以及如何实现?
答案 0 :(得分:0)
尝试这种方法:
@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);
}
}