Mybatis动态sql条件查询、判断空值和空字符串
下文笔者讲述mybatis动态sql条件查询的使用简介说明,如下所示
例:
例:
@Select("<script>" +
"SELECT * FROM table_name WHERE 1=1" +
"<if test='templateCode!=null'>" +
"and template_code = #{templateCode}" +
"</if>" +
"<if test='templateCode==null'>" +
"and (template_code IS NULL or template_code='')" +
"</script>")
相关参数说明
templateCode:参数信息 table_name:表名 template_code:数据库列名
以上脚本的功能
当传入templateCode为空时
则运行sql
select * from table_name
where 1=1
and (template_code IS NULL or template_code='');
当传入的templateCode不为空时
则运行sql
select * from table_name
where 1=1
and template_code = #{templateCode};
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


