[Email protected] annotation annotations
Role: Establishes the correspondence between the entity class and the database table.
Default rule: The first letter of the entity class class name is lowercase as the table name. Employee Class →employee table.
Usage: Specify the table name of the target database table in the Name property of the @table annotation
[Email protected] annotation annotations
Role: Establishes the correspondence between the entity class fields and the database table field.
Default rule:
Entity class fields: Camel-named
database table fields: Use "_" to differentiate individual words
Usage: Specify the field name of the Target field in the Name property of the @Column annotation to resolve the case where the database field does not correspond @Column ("Database actual field name")
[Email protected] annotation annotations
General Mapper There are two cases when executing the Xxxbyprimarykey (key) method.
Scenario 1: Explicitly specifying primary key fields without using @id annotations
SELECT emp_id,emp_name,emp_salary_apple,emp_age from tabple_emp WHERE emp_id =?
and Emp_name =? and emp_salary_apple =? and Emp_age =?
The above-mentioned WHERE clause is generated because the generic Mapper all the objects in the entity class
Fields are taken together as the Federated primary key.
Scenario 2: Use the @id primary key to explicitly mark the Entity class field corresponding to the primary key field in the database table
[Email protected] annotation annotations
Function: Allows general Mapper to write back the database automatically generated primary key values after the insert operation to the actual
The Body class object.
Self-increment primary key usage:
Sequence primary Key Usage:
Application scenario: Shopping Cart Checkout
? Increase sales of goods ...
? Reduce commodity inventory ...
? Generate order data → encapsulate to order object → save order object → database auto-generate primary key
Value → write back to the entity class object Order
? Generate a series of order details data →list<orderitem>→ set in each OrderItem
Primary key value of Order object as foreign key → Bulk Save list<orderitem>
@GeneratedValue (strategy = generationtype.identity)
- Depending on how the underlying database is automatically selected, the settings of the underlying database are required
- Like MySQL, the self-increment field is used, and the primary key needs to be set to auto_increment.
[email protected] PRIMARY key primary key
Used to mark entity class fields that do not correspond to a database table field.
@Transient
Private String otherthings; fields in non-database tables
Some annotations of Spring general Mapper