Mybatis uses <choose> <when>, mybatischoose
I. Requirements
The backend uses the orcale database and mybatis as the persistent layer. The frontend search function searches by type, but the database does not contain type fields,
Therefore, you must make a judgment in the where Condition Statement. When type = x1 and type = x2, the judgment conditions in where are different.
Ii. Solution
<Select id = "" resultMap = "">
Select * from table
<Where>
<If test = 'Type = "x1" '>
And condition 1;
</If>
<If test = 'Type = "x2" '>
And condition 2;
</If>
</Where>
</Select>
Or
<Select id = "" resultMap = "">
Select * from table
<Choose>
<When test = "type = 'x1'">
Where condition 1;
</When>
<When test = "type = 'x2'' ">
Where condition 2;
</When>
<Otherwise>
If none of the conditions in the when are met, use condition 3;
</Otherwise>
</Choose>
<If test = "type = 'x2 '"> // if there are other judgment conditions in addition to the preceding conditions, put them in the chose tag, and do not need to write where
And condition 2;
</If>
</Select>