Use of universal Mapper

Source: Internet
Author: User

    1. Use of universal Mapper
      1. Import dependency

<dependency>

<groupId>com.github.abel533</groupId>

<artifactid>mapper</artifactid>

<version>2.3.4</version>

</Dependency>

    1. Configure Plugins

<pluginInterceptor="Com.github.abel533.mapperhelper.MapperInterceptor" >

             <!-- primary key self-increment write method mysql, detailed description See document -->

             <property name= "IDENTITY" value= "MYSQL" />

             <!-- Universal mapper interface, multiple universal interfaces separated by commas -->

<propertyname="mappers"value="Com.github.abel533.mapper.Mapper" />

</plugin>

    1. The new mapper interface inherits the same mapper provided interface
      1. Inherit the generic mapper<t> You must specify a generic <T>

    1. Type of generic (entity Class) <T> must meet requirements

1. The table name uses the class name by default, and the hump turns to underline (only uppercase letters are processed), such as UserInfo the default corresponding table name is User_info .

2. Table name can be used @Table (name = "TableName") Specifies that the table name can be specified in this manner for non-conforming to the first default rule.

3. Field Default and @Column As a table field, the table defaults that the Java object's Field the name hump turns to underline form.

4, you can use @Column (name = "FieldName") Specify a field name that does not conform to rule 3rd

5. Use @Transient annotations can omit fields, and fields that add the annotations are not used as table columns.

6, the proposal must have a @Id Note as the primary key field, you can have more than one @Id The Annotated field is used as the Federated primary key.

    1. Testing the methods provided
    2. Generic Example Query object
      1. Add normal condition

Need to create an object Cirteria object out, through this object, to set some unconventional conditions

For example in the like > <

If there is or in the condition, then new to create a criteria object, and then use Example.or (CC2)

If you use sort: example. Setorderbyclause ("id ASC, age desc")

    1. Query criteria for adding or

    1. Add Sort function

Use of universal 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.