这个库是生成动态 SQL 语句的框架。可把它看作是一个类型安全的 SQL 模板库,另外还支持 MyBatis3 和 Spring JDBC 模板。

该库将生成格式化为由 MyBatis 或 Spring 使用的完整 DELETE,INSERT,SELECT 和 UPDATE 语句。

最常见的用例是生成语句和一组匹配的参数,这些参数可以被 MyBatis 直接使用。该库还将生成与 Spring JDBC 模板兼容的语句和参数对象。

该库通过实现一个类似 SQL 的 DSL 来创建一个对象,该对象包含完整的 SQL 语句以及该语句所需的任何参数。SQL 语句对象可以被 MyBatis 直接用作映射器方法的参数。

The library will generate these types of SQL statements:

  • DELETE statements with flexible WHERE clauses
  • INSERT statements of several types:
  • A statement that inserts a single record and will insert null values into columns (a "full" insert)
  • A statement that inserts a single record that will ignore null input values and their associated columns (a "selective" insert)
  • A statement that inserts into a table using the results of a SELECT statement
  • A parameter object is designed for inserting multiple objects with a JDBC batch
  • SELECT statements with a flexible column list, a flexible WHERE clause, and support for distinct, "group by", joins, unions, "order by", etc.
  • UPDATE statements with a flexible WHERE clause. Like the INSERT statement, there are two varieties of UPDATE statements:
  • A "full" update that will set null values
  • A "selective" update that will ignore null input values

项目地址

https://github.com/mybatis/mybatis-dynamic-sql