在rowmapper中设置数据

时间:2019-07-10 14:59:20

标签: java spring

尝试在rowmapper中设置自定义数据,但出现nullpointer异常。我正在尝试的是,如果name是某物,则忽略DB值,并在rowmapper中将其设置为0,但会得到nullpointer异常。我们可以在rowmapper中设置客户数据吗?如果我不在rowmapper中使用if,那么我将从db获取常规值。我的问题是我可以将其映射到自定义值即0,还是必须将其映射到表中的特定行。

public class StudentMapper implements RowMapper<StudentDAO> {

    public StudentNumber mapRow(ResultSet rs, int rowNum) throws SQLException {
        RowMapper<StudentDAO> stdao = new RowMapper<StudentDAO> ();

        bean.setName(rs.getString("Name"));
        bean.setPin(rs.getInt("Pin"));

        if(rs.getString("Name").equals("John")){
           stdao.setPin(0);
        } else {
           stdao.setPin(rs.getInt("Pin"));
        }

        return stdao;

    }
}

0 个答案:

没有答案