Mybatis动态SQL拼接
- <!—需求1:
- 根据作者名字和博客名字来查询博客!
- 如果作者名字为空,那么只根据博客名字查询,反之,则根据作者名来查询
- select * from blog where title = #{title} and author = #{author}
- —>
- select * from blog where
- title = #{title}
- and author = #{author}
select * from blog title = #{title} and author = #{author}
- update blog
- title = #{title},
- author = #{author}
- where id = #{id};
- select * from blog
- title = #{title}
- and author = #{author}
- and views = #{views}
-
- select * from blog
- <!—
- collection:指定输入对象中的集合属性
- item:每次遍历生成的对象
- open:开始遍历时的拼接字符串
- close:结束时拼接的字符串
- separator:遍历对象之间需要拼接的字符串
- select * from blog where 1=1 and (id=1 or id=2 or id=3)
- —>
- id=#{id}
title = #{title} and author = #{author}
select * from blog