初始化
commit
9b6ba0c178
|
@ -0,0 +1,38 @@
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
|
@ -0,0 +1,8 @@
|
||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="workspaceImportForciblyTurnedOn" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>rikao7</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- lombok依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.22</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,48 @@
|
||||||
|
package org.example;
|
||||||
|
|
||||||
|
import org.example.domain.Student;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StudentApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
// 设置编码(仅在需要时启用)
|
||||||
|
try {
|
||||||
|
System.setOut(new java.io.PrintStream(System.out,true,"UTF-8"));
|
||||||
|
} catch (java.io.UnsupportedEncodingException e) {
|
||||||
|
System.err.println("无法设置UTF-8编码:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建HashMap对象
|
||||||
|
HashMap<Integer, Student> studentHashMap = new HashMap<>();
|
||||||
|
|
||||||
|
//创建两个学生对象
|
||||||
|
Student studentOne = new Student(1, "梦钰", 22, "男", new BigDecimal(100));
|
||||||
|
Student studentTwo = new Student(2, "钰萍", 18, "女", new BigDecimal(100));
|
||||||
|
|
||||||
|
//保存到HashMap集合中,键为学生编号,值为学生对象
|
||||||
|
studentHashMap.put(studentOne.getStudentId(),studentOne);
|
||||||
|
studentHashMap.put(studentTwo.getStudentId(),studentTwo);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("第一种entrySet遍历方法:");
|
||||||
|
for (Map.Entry<Integer, Student> studentEntry : studentHashMap.entrySet()) {
|
||||||
|
System.out.println("key:" + studentEntry.getKey() + " value:" + studentEntry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("\n第二种keySet遍历方法:");
|
||||||
|
for (Integer student : studentHashMap.keySet()) {
|
||||||
|
System.out.println("key:" + student + " value:" + studentHashMap.get(student));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("\n第三种values遍历方法:");
|
||||||
|
for (Student student : studentHashMap.values()) {
|
||||||
|
System.out.println( " value:" + student);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.example.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 学生实体类
|
||||||
|
* 定义一个学生类Student,包括学生姓名,年龄,性别,成绩基本信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Student {
|
||||||
|
/**
|
||||||
|
* 学生编号
|
||||||
|
*/
|
||||||
|
private Integer studentId;
|
||||||
|
/**
|
||||||
|
* 学生名称
|
||||||
|
*/
|
||||||
|
private String studentName;
|
||||||
|
/**
|
||||||
|
* 学生年龄
|
||||||
|
*/
|
||||||
|
private Integer studentAge;
|
||||||
|
/**
|
||||||
|
* 学生性别
|
||||||
|
*/
|
||||||
|
private String studentSex;
|
||||||
|
/**
|
||||||
|
* 学生成绩
|
||||||
|
*/
|
||||||
|
private BigDecimal studentScore;
|
||||||
|
}
|
Loading…
Reference in New Issue