请注明出处:http://blog.csdn.net/qq_23179075/article/details/79005656
MyBatis中使用DATE_ADD()函数查询一个月的数据
在 MyBatis 的Mapper.xml 文件中使用 DATE_ADD() 函数查询指定月份的数据,DATE_ADD() 函数的使用方式传送门 ↓↓↓
MySQL: Mapper.xml
<select id="getByMonth" resultMap="RM">
SELECT
<include refid="columns"/>
FROM
`idata`
WHERE
<![CDATA[`time` <= DATE_ADD(#{month, jdbcType=TIMESTAMP},INTERVAL 1 MONTH ) AND `time` >= #{month, jdbcType=TIMESTAMP}]]>
</select>
Oracle: Mapper.xml
<select id="getByMonth" resultMap="RM">
SELECT
<include refid="columns"/>
FROM
"IDATA"
WHERE
<![CDATA["TIME" <= DATE_ADD(#{month, jdbcType=TIMESTAMP},INTERVAL 1 MONTH ) AND "TIME" >= #{month, jdbcType=TIMESTAMP}]]>
</select>
Dao类
List<DataBean> getByMonth(@Param("month")Date month);