使用RowMapper和JdbcTemplate的更新方法面临错误

时间:2015-01-08 22:19:05

标签: java spring spring-mvc


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个错误,我无法弄明白:

  1. 类型RowMapper不是通用的
  2. 我无法使用BeanPropertySqlParameterSource对象作为参数进行更新。

0 个答案:

没有答案