diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..ee2c34b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Student.java b/Student.java deleted file mode 100644 index c5632db..0000000 --- a/Student.java +++ /dev/null @@ -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 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); - } -} diff --git a/yangpeng-modules/yangpeng-student/src/main/java/com/bwie/student/controller/StuController.java b/yangpeng-modules/yangpeng-student/src/main/java/com/bwie/student/controller/StuController.java index 17e8bd5..c3ce601 100644 --- a/yangpeng-modules/yangpeng-student/src/main/java/com/bwie/student/controller/StuController.java +++ b/yangpeng-modules/yangpeng-student/src/main/java/com/bwie/student/controller/StuController.java @@ -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 hashMap = new HashMap<>(); + HashMap 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 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 set = hashMap.keySet(); + Iterator iterator = set.iterator(); + while (iterator.hasNext()) { + Integer key = iterator.next(); + System.out.println(key + ":" + hashMap.get(key)); + } + } diff --git a/效果/7-专高6.docx b/效果/7-专高6.docx index 34837bb..918defa 100644 Binary files a/效果/7-专高6.docx and b/效果/7-专高6.docx differ