要实现动态传入表名、列名,需要做如下修改:sql里的属有变量取值都改成${xxxx},而不是#{xxx}
<delete id="deleteTableData" parameterType="java.util.Map" statementType="STATEMENT"> <![CDATA[ delete from ${table} where ${col} < ${date}]]> </delete>
${xxxx}:$将传入的数据直接显示生成在sql中,对于字符串数据,需要手动加上引号。
String dateStr = DateFormatUtils.format(date.getTime(), "yyyy-MM-dd HH:mm:ss");
dateStr = "'" + dateStr + "'";
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/16903.html