mybatis “case when” Error: Failed to process, please exclude the tableName or statementId.

Encountered when using case when in mybatis for condition filtering judgment

Failed to process, please exclude the tableName or statementId.

Such error messages are syntax errors
but I have no problem running SQL statements on the MySQL command line

//case when
WHERE dept.type = 1
AND 
(
CASE agent.dept_type
WHEN "agent" THEN dept.id=30
END
)
//When the agent's dept_type is "agent", the judgment that dept.id = 30 will be added

There is no problem running this SQL statement on the command line, but an error will be reported if it is executed on mybatis

//Modified
WHERE dept.type = 1
AND dept.id=
(
CASE agent.dept_type
WHEN "agent" THEN 30
END
)

Later, put dept.id outside to solve this problem

20190718 – Supplementary record: another problem is encountered. If the dept table is associated query, there may be no data. When the dept has no data, we can’t assign any parameters to dept.id and can’t affect the query of the data in the original table. I changed it to the following:

//Modified
WHERE dept.type = 1
AND (dept.id=
(
CASE agent.dept_type
WHEN "agent" THEN 30
ELSE 0
END
) or dept.id is null)

Add the judgment that dept.id is empty
(there are many ways to solve it in MySQL statements, but an error will be reported on mybatis – – |)

2019-7-30-supplementary notes:
if it is an empty string, you can’t use "" but change it to single quotation mark ''

CASE WHEN *** THEN ***
ELSE ""  =>Need to change to=> ELSE''

Read More: