Get the App
SLTechnology News&Howtos  ›  Development  › 

Analysis of attention points in the use of MyBatis General Mapper@Table annotations

Shulou Source: shulou.com Published: 2022-06-02 10:08:59 10月31日 Update

This article introduces the knowledge of "attention Analysis of the use of MyBatis General Mapper@Table annotations". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The role of MyBatis generic Mapper@Table annotations using @ Table annotations

Generally, it works on the class name of the pojo entity class. After using this annotation, the attributes of the pojo class will have a mapping relationship with the corresponding table field (similar to the tag). For a simple mapping relationship, there is no need to write tags in the xml file for mapping.

Then you need to change resultMap to resultType in the xml file.

The return type is the entity class name.

Configure the database table name for the mapping.

The problem that should be paid attention to in the use of general mapper is that the entity needs to have relevant annotations.

@ table, @ Id @ Colunm

For example:

@ Table (name = "user_register") public class UserRegister {/ * it is important to note that the primary key must be marked with Id * / @ Id private Integer id; @ Column (name = "user_id") private String userId; / / omit other properties and getter setter methods}. Secondly, you need to pay attention to something.

MapperScan should be specified under the Mapper folder, otherwise there will be an inexplicable problem of two interfaces with the same name.

For example:

@ MapperScan (basePackages = {"com.jdjr.common.dao", "com.jdjr.admin.mapper"}) dependencies for specific use

The corresponding version can be used.

Tk.mybatis mapper-spring-boot-starter ${mapper.version.spring-boot} "Note Analysis for the use of MyBatis General Mapper@Table annotations" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Annotations entities files analysis functions contents attributes more tags knowledge class names problems practical similar inexplicable successful learning and then no two dilemma Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology OPPO Reno Shulou Information vpn