import org.springframework.jdbc.core.RowMapper;//倒入包
import java.sql.ResultSet;
import java.sql.SQLException;
public class tbUser implements RowMapper {
private long id;
private String user;
private String password;
private String perms;
//get,set省略
//重写方法
@Override
public Object mapRow(ResultSet resultSet, int i) throws SQLException {
tbUser user = new tbUser();
user.setId(resultSet.getInt("id"));
user.setUser(resultSet.getString("user"));
user.setPassword(resultSet.getString("password"));
user.setPerms(resultSet.getString("perms"));
return user;
}
@Repository
public class UserDao {
@Autowired
JdbcTemplate jdbcTemplate;
public List<tbUser> uesrList() {
String sql = "select * from user";
//这里用的是query方法,不是queryForList
List<tbUser> list = jdbcTemplate.query(sql, new tbUser());
return list;
}
}
测试即可