为什么我在@RequestBody参数中获取空值?

时间:2017-10-16 17:19:43

标签: rest spring-mvc

我创建了一个简单的REST服务(POST)。但是当我从邮递员@RequestBody调用此服务时,没有收到任何值&获得nullPointer。

@RequestMapping(value=/searchEmployee,method = RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    @Timed
    public ResponseEntity<List<EmpDTO>> search(@RequestBody EmpSearchDTO empSearchDTO){
    String brId=empSearchDTO.getBrid();// null
    List<String> location=empSearchDTO.getLocation()//null
    Employee e=employeeRepository.findByEmployeeBrId(String brId);
    }

我的java Bean对象如下所示:

public class EmpSearchDTO{

private String brId;
private List<String> location;

public void setBrid(String brId){
brId=brId;
}

public String getBrid(){
return brId;
}

public void setLocation(List<String location){
location=location;
}

public List<String> getLocation(){
return location;
}
}

我在请求正文中传递的JSON是

empSearchDTO
    {
       "brId":"G1234",
       "location":["India"]
    }

0 个答案:

没有答案