每个 select、insert /、update 、delete 对应一个 MappedStatement 对象,每个MappedStatement 包含一个SqlSource,
一个SqlSource含有一个MixedSqlNode,静态sql
,${},include在解析mpper文件生成MixedSqlNode时,就已经被替换和解析、
DynamicSqlSource:处理动态sql,
RawSqlSource:处理静态sql,其内部装饰StaticSqlSource。
StaticSqlSource:处理静态sql,无论是静态sql,还是动态sql,最终的处理结果,都是静态sql。
ProviderSqlSource:处理注解Annotation形式的sql。
DynamicSqlSource和StaticSqlSource的最大区别在于:StaticSqlSource的String sql,可以直接获取使用,而DynamicSqlSource的String sql需要逐一根据条件解析并拼接出最终的sql,方能使用。
<select id="selectAllAuthors" resultType="org.apache.ibatis.domain.blog.Author">
select * from STUDENTS where 1 = 1
<choose>
<when test="name != null">
and name = #{name}
</when>
<when test="email != null">
and EMAIL = #{email}
</when>
<otherwise>
and PHONE = "123"
</otherwise>
</choose>
</select>
org.apache.ibatis.scripting.xmltags.XMLScriptBuilder.nodeHandlers(String)部分源码
NodeHandler nodeHandlers(String nodeName) {
Map