Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of data loss in Mybatis query

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to solve the problem of data loss in Mybatis query", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to solve the problem of data loss in Mybatis query".

Data loss during Mybatis query

The entity classes and mapper files in the company are generated by mybatis reverse engineering.

Previously, you directly used the annotation @ select (.) when using myabtis queries. I had a problem.

The results show that there is no problem with the database query, but some data deficiencies are not inserted into the specified fields, such as the successful storage of ID in the following figure, and the failure of Z40 databases ID department Z40 regions 103 to Z40 regions 113.

Come to the conclusion after investigation

If the database name is very standard, such as user_name, the field will be automatically converted to userName when the entity class is generated by the inverse plug-in.

However, if the database is named in the form of letters (including numbers) _ letters (including numbers), automatic mapping will fail and some data will not be set to the specified attribute.

Solution.

Some columns with irregular names need to be annotated and manually mapped.

Or write sql statements in xml directly in the mapper.xml file. In general, the mapping specification for columns is automatically generated in reverse engineering.

Some missing fields in Mybatis query (mysql)

Select xx1 field xx2 field xx3 field from A table where condition

When querying, the value of the xx1 field and the xx2 appear, but the xx3 does not come out.

1. (does the database field have a value? If you restart without adding a value, try again)

two。 Put the sql statement into mysql tools such as SQLyog or Navicat for MySQL to query, and first make sure that there is no problem with the result of the statement.

3. If there is no problem at this time, mostly because some sensitive foreign key fields are used in the database field, you can modify the names of these keys appropriately.

(remember that the corresponding entity class, the mybatis statement should also be modified.) add the database to save the data value and restart the program.

The above is all the contents of this article entitled "how to solve the problem of data loss in Mybatis query". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report