annotation |
Target |
Corresponding XML |
describe |
@CacheNamespace |
kind |
<cache> |
Configure caching for a given namespace (such as a class). Attributes: implemetation,eviction, flushInterval , size 和 readWrite 。 |
@CacheNamespaceRef |
kind |
<cacheRef> |
Refer to the cache of another namespace to use. Attribute: value , which is the fully qualified name of the class. |
@ConstructorArgs |
method |
<constructor> |
Collect a set of results to pass to the object constructor. property: value , which is an array of formal parameters |
@Arg |
method |
<arg> <idArg> |
Individual constructor arguments, part of the ConstructorArgs collection. Properties: id,column,javaType , typeHandler . The id attribute is a boolean value to identify the attribute used for comparison, similar to the <idArg> XML element |
@TypeDiscriminator |
method |
<discriminator> |
A set of instance values are used to determine the result mapping table now. Properties: Column, javaType , jdbcType typeHandler , cases . The cases property is an array of instances. |
@Case |
method |
<case> |
The value of a single instance and its corresponding map. Properties: value , type , results . The Results property is an array of results, so this annotation is very similar to the actual ResultMap , specified by the Results annotation below |
@Results |
method |
<resultMap> |
list of result maps, containing a particular result Details of how columns are mapped to attributes or fields. Attribute: value , an array of Result annotations |
@Result |
method |
<result> <id> |
Separate result mapping between columns and attributes or fields shoot. Properties: id , column , property , javaType ,jdbcType ,type Handler , one , many . The id attribute is a boolean value, the table shows the properties that should be used for comparison. The one attribute is for individual associations, similar to <association> , while the many attribute is for sets, and <collection> is similar. |
@One |
method |
<association> |
Separate property value mappings for complex types. Attributes: select , the mapped statement (that is, the mapper side method), which can load the appropriate class type instance. Note: The union mapping is in the Annotation API is not supported. |
@Many |
method |
<collection> |
Collection property mapping for complex types. Attributes: select , which is the fully qualified name of a mapper method that loads a set of instances of the appropriate type. Note: Union mappings are not supported in Java annotations. |
@Options |
method |
Attributes of Mapping Statements |
This annotation provides access to a broad range of exchange and configuration options, which typically appear as properties on map statements. Rather than complicating each statement annotation, the Options annotation provides a coherent and clear way to access them. property: useCache=true , flushCache=false , resultSetType=FORWARD_ONLY, statementType=PREPARED, fetchSize= -1,timeout=-1 , useGeneratedKeys=false , keyProperty=”id“。 理解Java 注解是很重要的,因为没有办法来指定“null ”作为值。因此,一旦你使用了 Options注解,语句就受所有默认值的支配。要注意什么样的默认值来避免不期望的行为 |
@Insert @Update @Delete |
方法 |
<insert> <update> <delete> |
这些注解中的每一个代表了执行的真实 SQL。它们每一个都使用字符串数组(或单独的字符串)。如果传递的是字符串数组,它们由每个分隔它们的单独空间串联起来。属性:value,这是字符串数组用来组成单独的SQL语句 |
@InsertProvider @UpdateProvider @DeleteProvider @SelectProvider |
方法 |
<insert> <update> <delete> <select> 允许创建动态 SQL。 |
这些可选的SQL注解允许你指定一个 类名和一个方法在执行时来返回运行 的SQL。基于执行的映射语句, MyBatis 会实例化这个类,然后执行由 provider 指定的方法. 这个方法可以选择性的接 受参数对象作为它的唯一参数,但是必 须只指定该参数或者没有参数。属性: type,method。type 属性是类的完全限定名。method 是该类中的那个方法名。 |
@Param |
参数 |
N/A |
当映射器方法需多个参数,这个注解可以被应用于映射器方法参数来给每个参数一个名字。否则,多参数将会以它们的顺序位置来被命名。比如 #{1},#{2} 等,这是默认的。 使用@Param(“person”),SQL中参数应该被命名为#{person}。 |