Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从请求体中的Java列表中提取实体_Java_Json_Soapui - Fatal编程技术网

从请求体中的Java列表中提取实体

从请求体中的Java列表中提取实体,java,json,soapui,Java,Json,Soapui,我有以下方法 @PostMapping(value = Constants.EMPLOYEE_INSERT,produces = MediaType.APPLICATION_JSON_VALUE) public String employeeInsert(@RequestHeader(ConstantsValue.ID) @NotBlank final String id, @RequestBody final List<EmployeeData> empData)

我有以下方法

@PostMapping(value = Constants.EMPLOYEE_INSERT,produces = MediaType.APPLICATION_JSON_VALUE)
public String employeeInsert(@RequestHeader(ConstantsValue.ID) @NotBlank final String id,
        @RequestBody final List<EmployeeData> empData) {
    
    
    if (empData != null) {
        final List<EmployeeData> insertedData = this.employeeService.insertEmployeeData(empData, id);
        if (insertedData != null) {
            
            final List<EmployeeData> employeeDataAfterInsertion =
                           this.employeeService.getEmployeeData(employeeId);
            if (employeeDataAfterInsertion != null) {
                return new Gson().toJson(employeeDataAfterInsertion);
            } else {
                throw new EUCCustomException(empConstants.NO_EMPLOYEE_DATA);
            }
            
        } else {
            throw new EUCCustomException(empConstants.EMPLOYEE_INSERT_ERROR_DATA);
        }

    } else {
        throw new EUCCustomException(empConstants.EMPLOYEE_MISSING_HEADER_DATA);
    }

}
@PostMapping(value=Constants.EMPLOYEE\u INSERT,products=MediaType.APPLICATION\u JSON\u value)
公共字符串employeeInsert(@RequestHeader(ConstantsValue.ID)@NotBlank最终字符串ID,
@请求主体最终列表(数据){
if(empData!=null){
最终列表insertedData=this.employeeService.insertEmployeeData(empData,id);
如果(插入数据!=null){
最终列表employeeDataAfterInsertion=
这个.employeeService.getEmployeeData(employeeId);
if(employeeDataAfterInsertion!=null){
返回新的Gson().toJson(employeeDataAfterInsertion);
}否则{
抛出新的EUCCustomException(empConstants.NO_EMPLOYEE_数据);
}
}否则{
抛出新的EUCCustomException(empConstants.EMPLOYEE\u INSERT\u ERROR\u数据);
}
}否则{
抛出新的EUCCustomException(empConstants.EMPLOYEE\u缺少\u标头\u数据);
}
}

在请求中,我有一个empData列表,其中包含来自UI的数据。如何提取此empData,以便在getEmployeeData方法中传递employeeId。

EmployeeData应包含1个员工数据,如果EmployeeData是EmployeeData的列表,则它包含多个员工数据

你应该弄清楚你想抓住哪个员工,然后再使用这个id。 如果您想要第一个,可以将其用作:

  insertedData[0].getEmployeeId() 

getEmployeeId方法应存在于EmployeeData类中。

EmployeeData应包含1个员工数据,如果EmployeeData是EmployeeData的列表,则它包含多个员工数据

你应该弄清楚你想抓住哪个员工,然后再使用这个id。 如果您想要第一个,可以将其用作:

  insertedData[0].getEmployeeId() 

getEmployeeId方法应该存在于EmployeeData类中。

empData是否不为空?我的意思是,你肯定empData里面有价值,不是吗

使用foreach获取每个员工数据的值

for (EmployeeData employeeData : empData) { ... final List employeeDataAfterInsertion = this.employeeService.getEmployeeData(employeeData.getEmployeeId()); // make sure you have set the getter of getEmployeeId() inside EmployeeData class ... } for(EmployeeData EmployeeData:empData){ ... 最终列表employeeDataAfterInsertion= this.employeeService.getEmployeeData(employeeData.getEmployeeId());//确保已在employeeData类中设置getEmployeeId()的getter ... }
empData是否不为空?我的意思是,你肯定empData里面有价值,不是吗

使用foreach获取每个员工数据的值

for (EmployeeData employeeData : empData) { ... final List employeeDataAfterInsertion = this.employeeService.getEmployeeData(employeeData.getEmployeeId()); // make sure you have set the getter of getEmployeeId() inside EmployeeData class ... } for(EmployeeData EmployeeData:empData){ ... 最终列表employeeDataAfterInsertion= this.employeeService.getEmployeeData(employeeData.getEmployeeId());//确保已在employeeData类中设置getEmployeeId()的getter ... }
谢谢Garnight我已经试过了,但是编译器要求返回,即使我的函数中有返回。谢谢Garnight我已经试过了,但是编译器要求返回,即使我的函数中有返回