Integer queryDaNumByParam(@Param("timeType") String timeType,
@Param("dazt") Integer dazt, @Param("tableName") String tableName);
timeType 参数是字符串 和数字比较时 必须使用双引号 下面是错误的
<select id="queryDaNumByParam" resultType="java.lang.Integer">
SELECT
count( id ) AS num
FROM
${tableName}
WHERE DAZT = #{dazt}
<if test="timeType == '1'">
AND TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ) >= trunc( SYSDATE, 'day' ) + 1
AND TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ) <= trunc( SYSDATE, 'day' ) + 8
</if>
<if test="timeType == '2'">
AND TO_CHAR( TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ), 'YYYY-MM' ) = TO_CHAR( SYSDATE, 'YYYY-MM' )
</if>
<if test="timeType == '3'">
AND TO_CHAR( TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ), 'YYYY' ) = TO_CHAR( SYSDATE, 'YYYY' )
</if>
</select>
应该为下面这种
<select id="queryDaNumByParam" resultType="java.lang.Integer">
SELECT
count( id ) AS num
FROM
${tableName}
WHERE DAZT = #{dazt}
<if test='timeType == "1" '>
AND TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ) >= trunc( SYSDATE, 'day' ) + 1
AND TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ) <= trunc( SYSDATE, 'day' ) + 8
</if>
<if test='timeType == "2" '>
AND TO_CHAR( TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ), 'YYYY-MM' ) = TO_CHAR( SYSDATE, 'YYYY-MM' )
</if>
<if test='timeType == "3" '>
AND TO_CHAR( TO_DATE( CJSJ, 'yyyy-mm-dd hh24:mi:ss' ), 'YYYY' ) = TO_CHAR( SYSDATE, 'YYYY' )
</if>
</select>