遍历对象/列表

时间:2020-06-16 04:55:59

标签: java json spring list

我编写了所有类,以更好地理解我要实现的目标。 我在循环时遇到问题,或者是否还有其他选择。.我感到困惑的是,目前我的索引设置为0。如何遍历列表并执行功能

if(empgrouping = group-A){use group-A position and ID} 
else
if(empgrouping = group-B){use group-B position and ID} 

private Employeesset employeesset (String personal, String empgrouping) throws Exception{
    Employeesset emp = new Employeesset();

    Details details = employeeconfig.getempdepts().get(0);

    if(emp.flagistrue()&&empgrouping.equals(“group-A”){
           emp.setemplgroup(empgrouping);
           emp.setposition(“”);
           emp.setidentification(“”);
    }else{
  // choose group b or c//

——————————————————

“employee_details”:[
{“Employees  “: ”group-A“,
“Position  “: ”management“,
“ID “: ”333iisdsa“,
“Environments” :
 [  
    "name":"Shyam",   
    "name":"Bob", 
    "name":"Jai"
]} ,
{"Employees  “: ”group-B”,
“Position  “: ”management“,
“ID “: ”4455iisdf“,
“Environments” :
[  
      "name”:”sam”, 
    "name”:”loki”,  
    "name”:”avenger” 
]},
{"Employees  “: ”group-c“,
“Position  “: ”management“,
“ID “: ”234kkdk“,
“Environments” : [  
    "name”:”super”, 
    "name”:”kam”,  
    "name”:”mike”
]}    
]

————————————————

public static class Details{
@Jsonproperty(“Employees”)
String emptype;

@Jsonproperty(“Position”)
String position;

@Jsonproperty(“ID”)
String identification;

@Jsonproperty(“environments”)
List<Environments> environments;

//Getters and setters//

————————————

public class employeeconfig{
@Jsonproperty(“employee_details”);
List<Details> empdepts;

//getters and setters//

——————————————

public class Employeesset{
private employee;
private position;
private identification;

//getters and setters//

1 个答案:

答案 0 :(得分:1)

首先,您需要更改已编写的Employeesset的Class的代码的整体结构,该结构应为EmployeesSet,然后方法应始终遵循与变量相同的驼峰式结构

private EmployeesSet employeesSet (String personal, String empGrouping) throws Exception{
    EmployeesSet emp = new EmployeesSet();

     employeeConfig.getempdepts().foreach(resultDetails->{

//Write your code logic here                                //Using jdk 8
}

    if(emp.flagistrue()&&empGrouping.equals(“group-A”){
           emp.setemplgroup(empGrouping);
           emp.setposition(“”);
           emp.setidentification(“”);
    }else{
相关问题