文章目录
一、修改StudentInfo项目输出学生信息
1、打开项目
2、创建学生实体类Student
(1)、在main/java下创建net.tp.lesson01.bean包
(2)、创建学生实体类Student
package net.tp.lesson01.bean;
public class Student {
private String id;
private String name;
private String gender;
private int age;
private String major;
private String telephone;
private String email;
private String hobby;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
@Override
public String toString() {
return "Student{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", gender='" + gender + '\'' +
", age=" + age +
", major='" + major + '\'' +
", telephone='" + telephone + '\'' +
", email='" + email + '\'' +
", hobby='" + hobby + '\'' +
'}';
}
}
3、给学生类添加注解
- 添加注解@Component,交给Spring去管理
- 添加注解@ConfigurationProperties(prefix = “person”)
4、在application.properties里添加相关配置
5、解决输出结果的汉字乱码问题
-
setting->editor->File Encodings
-
设置后再次重启IDEA乱码,再一次使用JDK工具native2ascii.exe将汉字处理成uncode编码
D:\ldeaProjects\StudentInfo>cd src/main/resources
D:\ldeaProjects\StudentInfo\src\main\resources>native2ascii -encoding utf8 application.properties
#\u914D\u7F6Estudent\u5BF9\u8C61
student.id:20190101
student.name:\u5F20\u4E09
student.gender:\u7537
student.age:19
student.major:\u5927\u6570\u636E\u4E13\u4E1A
student.telephone:15989891140
student.email:maths007@163.com
student.hobby:\u7F16\u7A0B\u3001\u65C5\u6E38\u3001\u7F8E\u98DF
D:\ldeaProjects\StudentInfo\src\main\resources>
- 修改application.properties文件,汉字采用unicode编码形式