例如一段SQL查询出生年份是2005到2020年代的学生数量。
select * from user where Year(birthday) > 2005 and Year(birthday) < 2020;
不要吐槽为什么不用between,这里主要处理特殊字符问题。
解决办法:
<!-- 年龄段来查询-->
<select id="findYear" resultType="com.joy.test.mybatis.pojo.User">
select * from user
where Year(birthday) <![CDATA[>]]> 2005 and Year(birthday) <![CDATA[<]]> 2020
</select>
使用<![CDATA[你的特殊字符]]>来解析就可以!
本文介绍了一种在MyBatis中处理SQL特殊字符的方法,通过使用CDATA解析特殊字符,实现查询2005年至2020年间出生的学生数量。这种方法避免了常见的between操作,为SQL查询提供了一个新的解决方案。
1157

被折叠的 条评论
为什么被折叠?



