【问题标题】:iterate over objects/list遍历对象/列表
【发布时间】:2020-06-16 04:55:59
【问题描述】:

我编写了所有类以更好地理解我想要实现的目标。 我在循环时遇到问题,或者是否有其他选项。我感到困惑的是,目前我的索引设置为 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//

【问题讨论】:

    标签: java json spring list


    【解决方案1】:

    首先,您需要更改您编写的类的整个代码结构Employeesset 应该是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{
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-11
      • 2011-08-19
      • 2018-05-08
      • 2015-03-17
      • 2011-06-11
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      相关资源
      最近更新 更多