02 SQL 语句 where 1=1
select * from user where 1=1动态 SQL 拼接
String sql="select * from table_name where 1=1";
if (conditon 1) {
sql=sql+" and var2=value2";
}
if (conditon 2) {
sql=sql+" and var3=value3";
}<select id="findActiveBlogLike"
resultType="Blog">
SELECT * FROM BLOG
<where>
<if test="state != null">
state = #{state}
</if>
<if test="title != null">
AND title like #{title}
</if>
<if test="author != null and author.name != null">
AND author_name like #{author.name}
</if>
</where>
</select>查询表结构
最后更新于