|
1 | | -# Defining Entity Characteristics |
| 1 | +## 实体特性 |
2 | 2 |
|
3 | | -## Introduction |
| 3 | +### 学生实体特性: |
4 | 4 |
|
5 | | -This guide focuses on defining entity columns or characteristics in a Spring Boot project using JPA (Java Persistence API). |
| 5 | +- `id`(UUID):实体的主键。 |
| 6 | +- `name`(String):学生的姓名(不能为空)。 |
| 7 | +- `email`(String):学生的电子邮件地址(必须是有效的电子邮件地址)。 |
| 8 | +- `major`(String):学生的专业或研究领域(不能为空)。 |
| 9 | +- `year`(int):学生的年级(不能为空)。 |
| 10 | +- `international`(boolean):指示学生是否为国际学生(不能为空)。 |
6 | 11 |
|
7 | | -## Goal |
8 | | -The goal of this guide is to provide clear instructions for defining the characteristics of entities in a Spring Boot project with JPA, utilizing annotations to enforce constraints and behaviors for each attribute. |
| 12 | +### 定义 `id` 属性 |
9 | 13 |
|
10 | | - |
11 | | -## Entity Characteristics |
12 | | - |
13 | | -### Student Entity Characteristics: |
14 | | -- `id` (UUID): Primary key for the entity. |
15 | | -- `name` (String): Name of the student (must not be blank). |
16 | | -- `email` (String): Email address of the student (must be a valid email address). |
17 | | -- `major` (String): Major or field of study of the student (must not be blank). |
18 | | -- `year` (int): Year of study for the student (must not be null). |
19 | | -- `international` (boolean): Indicates if the student is international (must not be null). |
20 | | - |
21 | | -### Define `id` Attribute |
22 | | - |
23 | | -Add the `id` attribute to the `Student` class. This attribute will serve as the primary key for the entity. |
| 14 | +向 `Student` 类添加 `id` 属性。该属性将作为实体的主键。 |
24 | 15 |
|
25 | 16 | ```java |
26 | 17 | @Id |
27 | 18 | @GeneratedValue(strategy = GenerationType.AUTO) |
28 | 19 | private UUID id; |
29 | 20 | ``` |
30 | 21 |
|
31 | | -- `@Id`: Indicates that this field is the primary key for the entity. |
32 | | -- `@GeneratedValue`: Specifies the strategy for generating primary key values automatically. |
| 22 | +- `@Id`:表示该字段是实体的主键。 |
| 23 | +- `@GeneratedValue`:指定生成主键值的策略。 |
33 | 24 |
|
34 | | -### Define `name` Attribute |
| 25 | +### 定义 `name` 属性 |
35 | 26 |
|
36 | | -Add the `name` attribute to the `Student` class. This attribute represents the name of the student and must not be blank. |
| 27 | +向 `Student` 类添加 `name` 属性。该属性表示学生的姓名,不能为空。 |
37 | 28 |
|
38 | 29 | ```java |
39 | 30 | @NotBlank |
40 | 31 | private String name; |
41 | 32 | ``` |
42 | 33 |
|
43 | | -- `@NotBlank`: Ensures that the value of `name` is not null and contains at least one non-whitespace character. |
| 34 | +- `@NotBlank`:确保 `name` 的值不为 null 并包含至少一个非空白字符。 |
44 | 35 |
|
45 | | -### Define `email` Attribute |
| 36 | +### 定义 `email` 属性 |
46 | 37 |
|
47 | | -Add the `email` attribute to the `Student` class. This attribute represents the email address of the student and must be a valid email address. |
| 38 | +向 `Student` 类添加 `email` 属性。该属性表示学生的电子邮件地址,必须是有效的电子邮件地址。 |
48 | 39 |
|
49 | 40 | ```java |
50 | 41 | @NotBlank |
51 | 42 | @Email |
52 | 43 | private String email; |
53 | 44 | ``` |
54 | 45 |
|
55 | | -- `@Email`: Validates that the value of `email` is a valid email address. |
| 46 | +- `@Email`:验证 `email` 的值是否为有效的电子邮件地址。 |
56 | 47 |
|
57 | | -### Define `major` Attribute |
| 48 | +### 定义 `major` 属性 |
58 | 49 |
|
59 | | -Add the `major` attribute to the `Student` class. This attribute represents the major or field of study of the student and must not be blank. |
| 50 | +向 `Student` 类添加 `major` 属性。该属性表示学生的专业或研究领域,不能为空。 |
60 | 51 |
|
61 | 52 | ```java |
62 | 53 | @NotBlank |
63 | 54 | private String major; |
64 | 55 | ``` |
65 | 56 |
|
66 | | -- `@NotBlank`: Ensures that the value of `major` is not null and contains at least one non-whitespace character. |
| 57 | +- `@NotBlank`:确保 `major` 的值不为 null 并包含至少一个非空白字符。 |
67 | 58 |
|
68 | | -### Define `year` Attribute |
| 59 | +### 定义 `year` 属性 |
69 | 60 |
|
70 | | -Add the `year` attribute to the `Student` class. This attribute represents the year of study for the student and must not be null. |
| 61 | +向 `Student` 类添加 `year` 属性。该属性表示学生的年级,不能为空。 |
71 | 62 |
|
72 | 63 | ```java |
73 | 64 | @NotNull |
74 | 65 | private int year; |
75 | 66 | ``` |
76 | 67 |
|
77 | | -- `@NotNull`: Ensures that the value of `year` is not null. |
| 68 | +- `@NotNull`:确保 `year` 的值不为 null。 |
78 | 69 |
|
79 | | -### Define `international` Attribute |
| 70 | +### 定义 `international` 属性 |
80 | 71 |
|
81 | | -Add the `international` attribute to the `Student` class. This attribute indicates whether the student is international and must not be null. |
| 72 | +向 `Student` 类添加 `international` 属性。该属性表示学生是否为国际学生,不能为空。 |
82 | 73 |
|
83 | 74 | ```java |
84 | 75 | @NotNull |
85 | 76 | private boolean international; |
86 | 77 | ``` |
87 | 78 |
|
88 | | -- `@NotNull`: Ensures that the value of `international` is not null. |
89 | | - |
90 | | - |
91 | | -You can repeat the previous steps to create entity characteristics for the `Course` and `Enrollment` entities, ensuring appropriate annotations are applied to each attribute. |
| 79 | +- `@NotNull`:确保 `international` 的值不为 null。 |
92 | 80 |
|
93 | | -### Enrollment Entity Characteristics: |
| 81 | +您可以重复上述步骤,为 `Course` 和 `Enrollment` 实体创建实体特性,确保为每个属性应用适当的注释。 |
94 | 82 |
|
95 | | -- `id` (UUID): Primary key for the entity. |
96 | | -- `enrollmentDate` (Date): Date of enrollment. |
97 | | -- `grade` (int): Grade achieved in the course. |
| 83 | +### Enrollment 实体特性: |
98 | 84 |
|
99 | | -### Course Entity Characteristics: |
| 85 | +- `id`(UUID):实体的主键。 |
| 86 | +- `enrollmentDate`(Date):注册日期。 |
| 87 | +- `grade`(int):课程中获得的成绩。 |
100 | 88 |
|
101 | | -- `id` (UUID): Primary key for the entity. |
102 | | -- `name` (String): Name of the course. |
103 | | -- `instructor` (String): Name of the course instructor. |
104 | | -- `schedule` (String): Schedule details of the course. |
105 | | -- `capacity` (int): Maximum capacity of the course. |
106 | | -- `online` (boolean): Indicates if the course is online. |
107 | | -- `startDate` (Date): Start date of the course. |
| 89 | +### Course 实体特性: |
108 | 90 |
|
| 91 | +- `id`(UUID):实体的主键。 |
| 92 | +- `name`(String):课程名称。 |
| 93 | +- `instructor`(String):课程讲师姓名。 |
| 94 | +- `schedule`(String):课程的安排详情。 |
| 95 | +- `capacity`(int):课程的最大容量。 |
| 96 | +- `online`(boolean):指示课程是否在线。 |
| 97 | +- `startDate`(Date):课程的开始日期。 |
109 | 98 | --- |
110 | 99 |
|
111 | | -# [Next: Managing Relationships](relationships.md) |
| 100 | +# [下一步:管理关系](relationships.md) |
0 commit comments