java - 将字符串列表传递给声明的类文件
问题描述
大家好,下面是我的Employeeinformation类文件java。我必须通过java代码将值传递给它我很好地传递字符串,但我无法传递技术列表和字符串列表。
技术.java
package com.ElasticSearchCrud.ElasticSearchCrud;
import lombok.Data;
@Data
public class Technologies {
private String name;
private String yearsOfExperience;
}
员工信息.java
package com.ElasticSearchCrud.ElasticSearchCrud;
import lombok.Data;
import java.util.List;
@Data
public class EmployeeInformation {
private String id;
private String firstName;
private String lastName;
private List<Technologies> technologies;
private List<String> emails;
public EmployeeInformation(String id, String firstName, String lastName, List<Technologies> technologies, List<String> emails) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.technologies = technologies;
this.emails = emails;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public List<Technologies> getTechnologies() {
return technologies;
}
public void setTechnologies(List<Technologies> technologies) {
this.technologies = technologies;
}
public List<String> getEmails() {
return emails;
}
public void setEmails(List<String> emails) {
this.emails = emails;
}
}
将值传递给类文件
EmployeeInformation EmployeePost = new EmployeeInformation("3", "Vignesh", "Murali","?","?");
如何在上面的代码中传递技术列表和字符串列表。有人可以帮助我实现这一目标吗?
解决方案
List<Technologies> technologies = new ArrayList<>();
technologies.add(new Technologies("name1", "1999"));
technologies.add(new Technologies("name2", "1999"));
List<String> emails = new ArrayList<>();
strs.add("one");
strs.add("two");
EmployeeInformation EmployeePost = new EmployeeInformation("3", "Vignesh", "Murali",technologies,emails);
还将@AllArgsConstructor 添加到技术类。或者使用 setter 来初始化 Technologies 对象:
@Data
@AllArgsConstructor
public class Technologies {
private String name;
private String yearsOfExperience;
}
推荐阅读
- android - 通过电话验证 Firebase 不起作用
- c# - 从错误的数据表中解析 DateTime 列
- xml - xml-conduit:如何修改文档?
- typescript - how can i properly type the index signature on a nested for...in loop in typescript?
- c - Try to use += on string to stack char(s) in C
- javascript - Using (this) to select a specific instance of a class while hovering a parent element
- python - azorult_sploit.py:错误:需要以下参数:目标
- python - 如何在不留空格的情况下删除 Python 中的标点符号
- reactjs - React - 从错误的路径导入模块
- google-apps-script - 通过获取包含可能空行的数据的最后一行来保护特定范围