1.直接进入主题
@Select({"<script>",
"SELECT * FROM article a left join user u on a.`authorid` = u.`id` ",
"WHERE a.`isdelete` != 1 ",
"<if test='articleType != \"0\" '>",
"AND a.`articleType`= #{articleType}",
"</if>",
"<if test='userType != \"0\" '>",
"AND u.`state` = #{userType}",
"</if>",
"ORDER BY a.`createtime` ",
" DESC LIMIT #{currentPage}, #{PageCount}",
"</script>"})
List<Article> homePaging(
@Param("currentPage") Integer currentPage,
@Param("PageCount") Integer PageCount,
@Param("articleType") String articleType,
@Param("userType") String userType
);
2.解析
这个是笔者自己书写的可以完整运行的配置sql,亲测,可以参考
首先,一定要注意格式
{"<script>" ******"</script>" }
有种写脚本的感觉 HHH ,其次就是转义,我们在引号中还要用常量作为判断数据的时候,切记要加转义的斜杠
<if test='articleType != \"0\" '>