今天做搜索
搜索就是模糊查询,三个条件,用普通的sql语句不能实现,因为需要三个并列
所以用到了动态SQL语句,模糊查询还是一样的,只不过变成了if else
<select id="searchpaper" resultType="com.cvpr.bean.paper" parameterType="com.cvpr.bean.search">
select * from cvpr.papers
<where>
1=1
<if test="title != null">
and title like CONCAT('%',#{title},'%')
</if>
<if test="authors!=null">
and authors like CONCAT('%',#{authors},'%')
</if>
<if test="keywords !=null">
and keywords like CONCAT('%',#{keywords},'%')
</if>
<if test="times !=null">
<if test="times == '1'">
and original_link like CONCAT('%','2020','%')
</if>
<if test="times == '2'">
and original_link like CONCAT('%','2020','%') or original_link like CONCAT('%','2019','%')
</if>
</if>
</where>
</select>