手动拼装的sql : insert into tableA (id,name) values(:id,:name)
使用BeanPropertySqlParameterSource
执行:jdbcTemplate.update(sql, new BeanPropertySqlParameterSource(vo));
出问题了,
我跟代码进去 发现new BeanPropertySqlParameterSource(vo) 所有集合是空的,但是我的vo对象是有值的
-------------源码-------------
public int insertVo(SuperVo vo) throws Exception {
StringBuffer insert = new StringBuffer(" insert into ");
StringBuffer insert_value = new StringBuffer(" values ( ");
insert.append(vo.getTableName()).append(" ( ");
// 主键/序列
String pkFieldName = vo.getPKFieldName();
String sequence = vo.getSequence();
Integer seq = null;
if (pkFieldName != null) {
if (sequence != null && null == vo.getAttributeValue(vo.getPKFieldName())) {
seq = this.queryNextSeq(sequence);
vo.setAttributeValue(pkFieldName, seq);
} else {
seq = Util.getIntegerValue(vo.getAttributeValue(vo.getPKFieldName()));
}
}
List<String> list = vo.getAttributeNames();
int[] types = new int[list.size()];
Object[] params = new Object[list.size()];
String split = "";
for (int i = 0; i < list.size(); i++) {
String fieldName = list.get(i);
insert.append(split).append(fieldName);
insert_value.append(split).append(":").append(fieldName);
split = ",";
}
insert.append(")");
insert_value.append(")");
SqlParameterSource paramSource = new BeanPropertySqlParameterSource(vo);
String sql = insert.append(insert_value).toString();
jdbcTemplate.update(sql, new BeanPropertySqlParameterSource(vo));
}


虽然没有人回答,但是这个问题解决了,就此结贴。将数据缘转成namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
jdbcTemplate.getDataSource());就ok了。