春天没有抓住我休息请愿的所有对象

时间:2019-06-27 06:36:17

标签: java spring rest

我的方法是这样的:

@RequestMapping(value = "/asignar", method = RequestMethod.GET, headers = "Accept=application/json")
    public @ResponseBody
    ResponseViewEntity<ResultadoJSON> asignar(
            @RequestParam(required = true, value = "usuario") String usuario,           
            @RequestParam(required = true, value = "clienteId") Long clienteId,         
            ListaLotes lotes) {
....
}

对象ListaLotes

public class ListaLotes {   
    private List<LoteForm> lotes;
}

对象LoteForm

public class LoteForm {
    private Long loteId;
    private Long cantidad;
}

但是当我通过PostMan实现请愿时,对象“批注”它始终为空

PETITION REST

Rest Header

Rest body

我应该怎么做才能起作用?我无法修改Java代码作为API的一部分。只能修改de REST Petition

1 个答案:

答案 0 :(得分:1)

如前所述,如果要将数据传输到控制器,则需要使用POST方法并将参数标记为@RequestBody

// or @PostMapping
@RequestMapping(value = "/asignar", method = RequestMethod.POST, headers = "Accept=application/json")
    public @ResponseBody
    ResponseViewEntity<ResultadoJSON> asignar(
            @RequestParam(required = true, value = "usuario") String usuario,           
            @RequestParam(required = true, value = "clienteId") Long clienteId,         
            @RequestBody ListaLotes lotes) {
....
}