MyBatis动态传入表名,字段名参数的解决办法
原文:http://blog.csdn.net/yin_jw/article/details/27193317要实现动态传入表名、列名,需要做如下修改
[*]添加属性statementType="STATEMENT"
[*]注意statementType必须,且值必须是大写的STATEMENT,参数传入为多个,用map。
[*]同时sql里的属有变量取值都改成${xxxx},而不是#{xxx}
view plaincopyhttp://onexin.iyunv.com/source/plugin/onexin_bigdata/https://code.csdn.net/assets/CODE_ico.pnghttp://onexin.iyunv.com/source/plugin/onexin_bigdata/https://code.csdn.net/assets/ico_fork.svg
[*]<delete id="deleteTableData" parameterType="java.util.Map" statementType="STATEMENT">
[*] <!
[*] delete from ${table} where
[*] ${col} < ${date}]]>
[*]</delete>
1. statementType:STATEMENT(非预编译),PREPARED(预编译)或CALLABLE中的任意一个,这就告诉 MyBatis 分别使用Statement,PreparedStatement或者CallableStatement。默认:PREPARED。这里显然不能使用预编译,要改成非预编译。
2. ${xxxx}:$将传入的数据直接显示生成在sql中,对于字符串数据,需要手动加上引号。
view plaincopyhttp://onexin.iyunv.com/source/plugin/onexin_bigdata/https://code.csdn.net/assets/CODE_ico.pnghttp://onexin.iyunv.com/source/plugin/onexin_bigdata/https://code.csdn.net/assets/ico_fork.svg
[*]String dateStr = DateFormatUtils.format(date.getTime(), "yyyy-MM-dd HH:mm:ss");
页:
[1]