Using choose when otherwise in MyBatis to generate dynamic SQL
You can use choose when else in MyBatis to generate dynamic SQL.
The statement will be something like if else if else else.
First, enclose it in <choose>~</choose>.
The <when>~</when> are if and else if. Any number of ifs can be described.
Finally, <otherwise>~</otherwise> is described as the same meaning as else.
The following is an example.
<select id="selectA" parameterType="Map" resultType="String"> <choose> <when test="selectedSkirEmpty"> SELECT 0 FROM SYSIBM.SYSDUMMY1 </when> <otherwise> SELECT 1 FROM SYSTEM.SYSDUMMY1 </otherwise> </choose> </select>
In the above, there is one when, but it is possible to describe multiple whens.