Some annotations of Spring general Mapper

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.