Mybatis judges according to the non-empty time of id query.

write as follows:

select * from t_user t
where 1 = 1 
<if test="id != null and id != """>
    and t.id = -sharp{id}
</if>

if id is empty, all users will be found. What should I do?
if the id non-null judgment is made before the call, then the judgment in the mapper file is meaningless, can it be removed?

sincerely ask for advice, thank you ~

Jan.19,2022

since your business requirement is that all queries are not allowed, it is natural to check before the query and delete the non-empty judgment


from the query statement.

you can add an else:

  

this non-empty check is added to the controller bar

Menu