在我的Spring Boot REST API应用程序中,我需要通过接受强类型列表作为输入来处理HTTP POST:
@RestController public class CusttableController { static final Logger LOG = LoggerFactory.getLogger(CusttableController.class); @RequestMapping(value="/custtable/update", method=RequestMethod.POST) @ResponseBody public String updateCusttableRecords(List<Custtable> customers) { try { for (Custtable cust : customers) { Custtable customer = (Custtable) custtableDao.getById(Custtable.class, new CusttableCompositeKey (cust.getAccountnum(),cust.getPartition(),cust.getDataareaid()));
在该API的Jersey版本中,此方法工作正常,但使用Spring Boot,它会给我以下错误:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface
我在Spring Boot中接受强类型列表的正确方法是什么?
尝试将RequestBody批注添加到方法定义中
@RequestMapping(value="/custtable/update", method=RequestMethod.POST) @ResponseBody public String updateCusttableRecords(@RequestBody List<Custtable> customers) { //Method body }