Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of excluding unnecessary Fields in mybatis plus Associated Database

Shulou Source: shulou.com Published: 2022-06-01 06:30:43 11月01日 Update

Most people do not understand the knowledge points of this article "the method of excluding unnecessary fields in mybatis plus related database", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "mybatis plus related database excluding unnecessary fields" article.

Associated database excluding unnecessary fields java comes with / * virtual binding process current approver corresponding table field of transient * / private transient String status; declares that this field is static / * virtual binding process current approver corresponding table field * / private static String status Declare through annotations that the field is not a field in a database table / * Virtual binding process current approver corresponding table field * / @ TableField (exist = false) private String status

Which business scenario is used in which way?

If you want to support serialization without associating database fields, use @ TableField

If you just don't want to associate the database, you can use all three

In the project, since the data must be serialized and deserialized when exporting excel, it is true that using transient can exclude non-database fields, but it will also result in null when data is exported, so it is best to use @ @ TableField for this scenario.

Exclude custom fields and do not query the reason for the demand

Because the database table is designed as a group table

One is the parameter table under the corresponding group.

When querying the data, you want to look up the data pages under the corresponding group while querying the group table.

Therefore, a corresponding parameter is added under the group entity class to accept the corresponding group data.

Error screenshot

Error analysis

According to the query statement,

All fields are checked out by default in the conditional query.

However, an error was reported because the custom field does not exist in the database.

Try

The biggest problem here is how to exclude the custom fields and search the Internet.

Finally, I found it in the official documents of Mybatis-plus.

@ TableFiled has an exist property that defines whether the field is a database table field.

So add the attribute

Rerun

The above is about the content of this article on "the method of excluding unnecessary fields in mybatis plus related database". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

Tags: Fields data databases associations contents queries methods approvers sequences processes parameters and at the same time scenarios that is properties articles times knowledge articles errors Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MySQL Huawei Linux Microsoft