[35,"云南大学","云南","昆明市","普通本科","公办","综合类","双一流","2","1","2","1067300","575","16342"]这样的对象如何转为实体类
时间: 2023-09-06 17:08:21 浏览: 156
这个对象包含了云南大学的各种信息,可以定义一个实体类来表示它,如下所示:
```java
public class University {
private int id; // 学校ID
private String name; // 学校名称
private String province; // 所在省份
private String city; // 所在城市
private String level; // 学校类型(普通本科、独立学院等)
private String nature; // 学校性质(公办、民办等)
private String category; // 学校类别(综合类、理工类等)
private String doubleFirstClass; // 是否为双一流大学
private int ranking; // 学校排名
private int score; // 学校得分
private int totalScore; // 学校总分
private int code; // 学校代号
private int provinceCode; // 省份代码
private int cityCode; // 城市代码
// 构造方法
public University(int id, String name, String province, String city, String level, String nature, String category, String doubleFirstClass, int ranking, int score, int totalScore, int code, int provinceCode, int cityCode) {
this.id = id;
this.name = name;
this.province = province;
this.city = city;
this.level = level;
this.nature = nature;
this.category = category;
this.doubleFirstClass = doubleFirstClass;
this.ranking = ranking;
this.score = score;
this.totalScore = totalScore;
this.code = code;
this.provinceCode = provinceCode;
this.cityCode = cityCode;
}
// Getter和Setter方法
// 略
// toString方法
@Override
public String toString() {
return "University{" +
"id=" + id +
", name='" + name + '\'' +
", province='" + province + '\'' +
", city='" + city + '\'' +
", level='" + level + '\'' +
", nature='" + nature + '\'' +
", category='" + category + '\'' +
", doubleFirstClass='" + doubleFirstClass + '\'' +
", ranking=" + ranking +
", score=" + score +
", totalScore=" + totalScore +
", code=" + code +
", provinceCode=" + provinceCode +
", cityCode=" + cityCode +
'}';
}
}
```
然后你可以通过下面的代码将给定的对象转换为该实体类的实例:
```java
University university = new University(
35, "云南大学", "云南", "昆明市", "普通本科", "公办", "综合类", "双一流", 2, 1, 2, 1067300, 575, 16342
);
```
阅读全文