mybtais的mapper中使用@Select注解使用if
一、场景描述
在springboot项目中使用mybatis+mybatis-plus,为满足业务需要,在mapper中定义的方法中使用@Select映射SQL语句 注意事项 : 1.需要使用标签 script标签包裹 2.注意大于小于符号的使用时的转义 3.mybatis常用转义如下
< < > > <> <> & & ' " "
@Select({ "<script>"+ " select t.* from track_name t"+ " <where>"+ " <if test=username!= null and username !="" >"+ " and t.username=#{username}"+ " </if>"+ " <if test=gmtCreateTime!=null and gmtCreateTime !="" >"+ " and t.gmtCreateTime > #{gmtCreateTime} "+ " </if>"+ " </where>"+ "</script>" }) IPage<TrackName> queryCondition(Page<TrackName> page,@Param("username")String username,@Param("gmtCreateTime")String gmtCreateTime)
下一篇:
CISCN(web篇)命令执行