day7
parent
0ad95164f8
commit
1ea817c5df
|
@ -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>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
101
Student.java
101
Student.java
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bwie.student.controller;
|
package com.bwie.student.controller;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.Student;
|
||||||
import com.bwie.student.StudentApplication;
|
import com.bwie.student.StudentApplication;
|
||||||
import com.bwie.student.service.impl.StudentService;
|
import com.bwie.student.service.impl.StudentService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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 org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Classname StuController
|
* @Classname StuController
|
||||||
|
@ -27,18 +31,33 @@ public class StuController {
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
// 创建HashMap对象。(10 分)
|
// 创建HashMap对象。(10 分)
|
||||||
HashMap<Integer, String> hashMap = new HashMap<>();
|
HashMap<Integer, Student> hashMap = new HashMap<>();
|
||||||
// 创建两个学生对象。(10 分)
|
// 创建两个学生对象。(10 分)
|
||||||
String nameone = "yangpeng";
|
Student student1 = new Student(1, "yangpeng", 18, "男", 100);
|
||||||
String nametwo = "yangxufei";
|
Student student2 = new Student(2, "yangxufei", 18, "男", 100);
|
||||||
// 保存到HashMap集合中,键为学生编号,值为学生对象。(30 分)
|
// 保存到HashMap集合中,键为学生编号,值为学生对象。(30 分)
|
||||||
String nameonename = hashMap.put(1, nameone);
|
hashMap.put(student1.getStuId(), student1);
|
||||||
String nametwoname = hashMap.put(2, nametwo);
|
hashMap.put(student2.getStuId(), student2);
|
||||||
|
|
||||||
// 三种方式遍历输出集合中的元素信息。(30 分)
|
// 三种方式遍历输出集合中的元素信息。(30 分)
|
||||||
System.out.println(hashMap);
|
|
||||||
System.out.println(nameonename);
|
System.out.println("第一种遍历方式");
|
||||||
System.out.println(nametwoname);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
效果/7-专高6.docx
BIN
效果/7-专高6.docx
Binary file not shown.
Loading…
Reference in New Issue