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>")

Menu