发布网友 发布时间:2024-10-24 16:40
共3个回答
热心网友 时间:2024-11-06 13:35
public List<Company> getCompanies() throws SQLException {
return jdbcTemplate.query(
"SELECT id, name FROM company WHERE user_id = ? AND deleted = 0 ORDER BY name",
new ParameterizedRowMapper<Company>() {
public Company mapRow(ResultSet rs, int i) throws SQLException {
return new Company(
rs.getInt(1),
rs.getString(2)
);
}
},
userId
);
}
热心网友 时间:2024-11-06 13:41
还是用ibatis方便,自动生成数据库操作接口,里面有你需要的大部分操作,返回list[object]是有的
热心网友 时间:2024-11-06 13:35
List<Object[]> list=jdbcTemplate.query("select * from XXX", new RowMapper<Object[]>() {
@Override
//这个数组的大小根据你的表的列数来定哦
public Object[] mapRow(ResultSet resultSet, int rownum) throws SQLException {
Object[] objects=new Object[6];
objects[0]=resultSet.getString(1);
objects[1]=resultSet.getString(2);
objects[2]=resultSet.getString(3);
objects[3]=resultSet.getString(4);
objects[4]=resultSet.getString(5);
objects[5]=resultSet.getString(6);
return objects;
}
});