About the record that the orderBy was written in the entity class and caused an error

There was a problem during the test sort

 However, it is written like this in mybatis

After a lot of tests, I couldn't find the reason why order by 0 appears.

Later, I searched for the meaning of order 0:

meaning:

order by 1 or order by 2...order by N in the sql statement

In fact, 1 means the first field, and 2 means the second field; 

By analogy, when there are only 2 fields in the table, oder by 3 will be wrong. This is no different from the order by column name, but it is still very useful in special cases.

Notice:

ORDER BY ASC should not be written in this way, after ORDER BY is either a field or a number;

Can ORDER BY 1 ASC or ORDER BY COL1 ASC;

ASC means sort in ascending order, DESC means sort in descending order

This is my pass parameter

 Because the select query cannot have the 0th column, it will report the error of the beginning picture, order by 1 is to sort according to the first field of the search, but this is not the sort I want, I think it is because of the entity class Having orderBy in will directly affect the sorting. Sure enough, I deleted the sorting of mybatis. When I pass parameters in orderBy, as many as I pass, there will be order by in sql. The problem is solved when I replace orderBy with sortBy in the entity class.

 Summary: Try to avoid keywords in SQL in entity classes to avoid problems.

Supongo que te gusta

Origin blog.csdn.net/weixin_55823910/article/details/126778877
Recomendado
Clasificación