public class PersonDAO {
private JdbcTemplate jdbc ;
public void setDataSource(DataSource jdbc){
this.jdbc = new JdbcTemplate(jdbc);
}
public List GetPersonDetails(){
return jdbc.query("select * from person", new RowMapper(){
public Person mapRow(ResultSet rs, int rowNum) throws SQLException {
Person person = new Person();
person.setName(rs.getString("Name"));
person.setEmail(rs.getString("Email"));
person.setPhone(rs.getInt("Phone"));
person.setSex(rs.getString("Sex"));
return person;
}
});
}
public boolean InsertPersonDetail(Person person){
BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(person);
return jdbc.update("insert into Person (Name , Email , Text ,Phone) values ( :Name , :Email , :Text ,:Phone)" , params)== 1;
}
}
我面临2个错误,我无法弄明白:
RowMapper
不是通用的BeanPropertySqlParameterSource
对象作为参数进行更新。