mybatis的where 1=1的作用

来源:互联网 发布:用友致远软件 编辑:程序博客网 时间:2024/05/20 07:34
1=1 永真, 1<>1 永假。 select * from sys_voter where 1<>1 这句查询出来的是 只要表结构不要表数据;select * from sys_voter t where 1=1  查询全部数据 相当于 select * from sys_voter t ;那么这句的话有啥作用呢??sql语句a : select * from sys_voter t where 1=1 and t.id_='c7d958305c8144c7a1cdf8c7045583d'当你的 字段 id_ 值为空时,保证 sql语句a 还能一直运行不报错,也就是说 用户在条件查询时候 你用了 where 1=1 ;无论用户是否查询了 你都可以不用判断某个字段  为空不为空!!!
原创粉丝点击