master
yangpeng 2024-07-25 09:43:13 +08:00
parent 0ad95164f8
commit 1ea817c5df
5 changed files with 47 additions and 109 deletions

View File

@ -0,0 +1,14 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AliAccessStaticViaInstance" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliDeprecation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliEqualsAvoidNull" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliMissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliWrapperTypeEquality" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,101 +0,0 @@
import java.util.HashMap;
/**
* @Classname Student
* @Description TODO
* @Date 2024/7/25 9:07
* @Created by
*/
public class Student {
/**
*
*/
private Integer stuId;
/**
*
*/
private String stuName;
/**
*
*/
private Integer stuAge;
/**
*
*/
private String stuSex;
/**
*
*/
private Integer stuScore;
public Integer getStuId() {
return stuId;
}
public void setStuId(Integer stuId) {
this.stuId = stuId;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public Integer getStuAge() {
return stuAge;
}
public void setStuAge(Integer stuAge) {
this.stuAge = stuAge;
}
public String getStuSex() {
return stuSex;
}
public void setStuSex(String stuSex) {
this.stuSex = stuSex;
}
public Integer getStuScore() {
return stuScore;
}
public void setStuScore(Integer stuScore) {
this.stuScore = stuScore;
}
public Student() {
}
public Student(Integer stuId, String stuName, Integer stuAge, String stuSex, Integer stuScore) {
this.stuId = stuId;
this.stuName = stuName;
this.stuAge = stuAge;
this.stuSex = stuSex;
this.stuScore = stuScore;
}
public static void main(String[] args) {
// 创建HashMap对象。10 分)
HashMap<Integer, String> hashMap = new HashMap<>();
// 创建两个学生对象。10 分)
String nameone = "yangpeng";
String nametwo = "yangxufei";
// 保存到HashMap集合中键为学生编号值为学生对象。30 分)
String nameonename = hashMap.put(1, nameone);
String nametwoname = hashMap.put(2, nametwo);
// 三种方式遍历输出集合中的元素信息。30 分)
System.out.println(hashMap);
System.out.println(nameonename);
System.out.println(nametwoname);
}
}

View File

@ -1,5 +1,6 @@
package com.bwie.student.controller;
import com.bwie.common.domain.Student;
import com.bwie.student.StudentApplication;
import com.bwie.student.service.impl.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
@ -11,6 +12,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* @Classname StuController
@ -27,18 +31,33 @@ public class StuController {
public void test() {
// 创建HashMap对象。10 分)
HashMap<Integer, String> hashMap = new HashMap<>();
HashMap<Integer, Student> hashMap = new HashMap<>();
// 创建两个学生对象。10 分)
String nameone = "yangpeng";
String nametwo = "yangxufei";
Student student1 = new Student(1, "yangpeng", 18, "男", 100);
Student student2 = new Student(2, "yangxufei", 18, "男", 100);
// 保存到HashMap集合中键为学生编号值为学生对象。30 分)
String nameonename = hashMap.put(1, nameone);
String nametwoname = hashMap.put(2, nametwo);
hashMap.put(student1.getStuId(), student1);
hashMap.put(student2.getStuId(), student2);
// 三种方式遍历输出集合中的元素信息。30 分)
System.out.println(hashMap);
System.out.println(nameonename);
System.out.println(nametwoname);
System.out.println("第一种遍历方式");
for (Map.Entry<Integer, Student> entry : hashMap.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
System.out.println("第二种遍历方式");
for (Integer key : hashMap.keySet()) {
System.out.println(key + ":" + hashMap.get(key));
}
System.out.println("第三种遍历方式");
Set<Integer> set = hashMap.keySet();
Iterator<Integer> iterator = set.iterator();
while (iterator.hasNext()) {
Integer key = iterator.next();
System.out.println(key + ":" + hashMap.get(key));
}
}

Binary file not shown.