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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e46825-44bbc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e46825-44bbc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?