方法:boolean delete(String tableName, String primaryKey, Record record)
3.3版本
public boolean delete(String tableName, String primaryKey, Record record) {
String[] pKeys = primaryKey.split(",");
if (pKeys.length <= 1) {
return this.deleteById(tableName, primaryKey, record.get(primaryKey));
} else {
this.config.dialect.trimPrimaryKeys(pKeys);
Object[] idValue = new Object[pKeys.length];
for(int i = 0; i < pKeys.length; ++i) {
idValue[i] = record.get(pKeys[i]);
if (idValue[i] == null) {
throw new IllegalArgumentException("The value of primary key \"" + pKeys[i] + "\" can not be null in record object");
}
}
return this.deleteById(tableName, primaryKey, idValue);
}
}
3.5版本
public boolean delete(String tableName, String primaryKey, Record record) {
String[] pKeys = primaryKey.split(",");
if (pKeys.length <= 1) {
return this.deleteById(tableName, primaryKey, (Object[])record.get(primaryKey));
} else {
this.config.dialect.trimPrimaryKeys(pKeys);
Object[] idValue = new Object[pKeys.length];
for(int i = 0; i < pKeys.length; ++i) {
idValue[i] = record.get(pKeys[i]);
if (idValue[i] == null) {
throw new IllegalArgumentException("The value of primary key \"" + pKeys[i] + "\" can not be null in record object");
}
}
return this.deleteById(tableName, primaryKey, idValue);
}
}
throw:********** cannot be cast to [Ljava.lang.Object;
解决办法如下:
1: 做一个 public MyDbPro extends DbPro ,并且覆盖掉你碰到问题的这个 delete 方法,将其中的:
return deleteById(tableName, primaryKey, record.get(primaryKey))
改成下面的代码:
return deleteById(tableName, primaryKey, (Object)record.get(primaryKey))
2:做一个public class MyDbProFactory implements IDbProFactory,内部代码如下:
public DbPro getDbPro(String configName) {
return new MyDbPro(configName);
}
3:将你自己的 MyDbPro 切换上去:
activeRecordPlugin.setDbProFactory(new MyDbProFactory());
记得搞定后回来再反馈一下,然后我可以将这个功能做到 jfinal 3.6 中去,感谢反馈