Dynamic SQL of mybatis

If you use ORM frameworks such as JDBC or hibernate, you often have to splice SQL as needed, which is a very troublesome thing. Mybatis provides the ability to assemble dynamic SQL, and it has only a few basic elements, which are simple and clear. A large number of judgments can be configured in the mapping file XML of mybatis, so as to meet the needs that we need to write a lot of code to achieve. Dynamic SQL reduces a lot of coding.

This reflects the advantages, configurability, flexibility and maintainability of mybatis.

Note that this example is based on the analysis and comparison of mybatis + hibernate + jdbc

The following is a demonstration of the examples in the above table:

If demo example:

Choosey demo example:

Interface class

Test class

Trim demo example:

Interface class:

Test class:

set

Test class:

Foreach will not be demonstrated here. Refer to my blog post batch update, which is written in detail

Of course, there is also bind, but this is not commonly used. The foreach mentioned above includes the dynamic SQL commonly used in the development process.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>