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> order by field3, @param4 </sql> <sql id="sql2"> ... </sql> </sqls>Every SQL tag should have an Id. The Id must be unique in the SQL XML file. It will be called by db.select or db.change. You can define params in SQL just write :param .
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.
The if tag can be nested. You can write comment in several ways. Pay attention to the mark "<". You must write it like "<" to match the xml diction.