test.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqls>
<sqls>
<sql id="sql1" paramPrefix=":" dynamicPrefix="@">
<!-- this is comment -->
/**
this is comment
**/
// this is comment
SELECT field1,field2,field3 FROM table1
WHERE
field1= :param1
<if exists="param2"> and field2 < :param2</if>
<if notexists="param2"> and field2 < 500</if>
<if istrue="param3.substr(0,1)=='x'"> and field3 = :param3 </if>
<if isfalse="param3.substr(0,1)=='x'"> and field3 = 'y' </if>
</sql>
<sql id="sql2">
<include groupId="test" sqlId="sql1"/>
order by field3, @param4
</sql>
</sqls>
The paramPrefix attribute of sql tag is an option. You can redefine it if ":" is a must char in your sql. You can add dynamic sql parts SQL just write @dynamic .
The dynamicPrefix attribute of sql tag is an option. You can redefine it if "@" is a must char in your sql. You can do deffient operation by judging whether a param is existed or not, or a javascript formula is true or not, by setting the exists notexists istrue isfalse attributes. The if tag can be nested. You can include an existed sql into your sql by setting the groupId sqlId attributes.
You can write comment in several ways. Pay attention to the mark "<". You must write it like "<" to match the xml diction.