请注明出处:http://blog.csdn.net/qq_23179075/article/details/79005656
在 MyBatis 的Mapper.xml 文件中使用 DATE_ADD() 函数查询指定月份的数据,DATE_ADD() 函数的使用方式传送门 ↓↓↓
<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>
<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>
List<DataBean> getByMonth(@Param("month")Date month);