MyBatis uses dynamic SQL on annotations (@ select uses if)

@Select({
            "<script>",
            "select * from user_info where 1=1",
            "<when test="name!=null and name!="" ">",
            "and name = -sharp{name}",
            "</when>",
            "</script>"})

the condition is that name is not empty and is not equal to"(empty string)
. How to write this? The above is written wrong

Jul.16,2022

try this

@Select("<script>" +
    "select * from user_info where 1=1" +
        "<where>" +
            "<if test=test='name!=null and name!=''>" +
                "and name = -sharp{name}"+
            "</if>" +
        "</script>")

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-1b30afc-2bd26.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-1b30afc-2bd26.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?