The <column name of the query result> in the database and the <property name> attribute in the java entity class will not match the problem

1. Problem Prophet

  • The MySQL database under the windous system is not case-sensitive.
    The <query result column name> username in the database will match the <attribute name> userName attribute in the java entity class.
  • On the Linux operating system, the MySQL database is strictly case-sensitive, and
    the above situation will not correspond

Second, the solution (find a way to correspond)

1. Alias ​​the columns of the database

insert image description here
Advantages:
fast speed, high efficiency, simple, it can be solved in sql statement.

2. A configuration method is provided in Mybatis <the corresponding relationship between the column name of the configuration query result and the attribute name of the entity class>2

Note: the return type becomes the above return a map map has our corresponding relationship

Disadvantage: need to parse one more xml file, the efficiency is not as high as the method
Advantage: convenient, no need to change the matching of all sql statements


Summarize

  1. The first method is to alias the database column names, which is simple and fast, and has great advantages for a small number of fields. When we need to change the fields, it is inconvenient for a long time.
  2. The second is an internal configuration method that we can use when we use the Mybatis framework.

Guess you like

Origin blog.csdn.net/qq_45973897/article/details/111563721