1. public PersonVo getInfo(int id) throws Exception {
2. QueryRunner queryRunner = new QueryRunner();
3. String sql = "select * from person where id = " + id;
4. return (PersonVo)queryRunner.query(getConnection(), sql,new BeanHandler(PersonVo.class));
5. }
public PersonVo getInfo(int id) throws Exception {
QueryRunner queryRunner = new QueryRunner();
String sql = "select * from person where id = " + id;
return (PersonVo)queryRunner.query(getConnection(), sql,new BeanHandler(PersonVo.class));
1. PersonVo pv = new Test().getInfo(1);
2. System.out.println(pv.getUsername());
PersonVo pv = new Test().getInfo(1);
System.out.println(pv.getUsername());
如果结果有一条以上,就要用BeanListHandler,MapListHandler.
如:
1. public List<PersonVo> getRegist3() throws Exception {
2. QueryRunner queryRunner = new QueryRunner();
3. String sql = "select * from person";
4. return (List)queryRunner.query(getConnection(), sql,new BeanListHandler(PersonVo.class));
5. }
public List<PersonVo> getRegist3() throws Exception {
QueryRunner queryRunner = new QueryRunner();
String sql = "select * from person";
return (List)queryRunner.query(getConnection(), sql,new BeanListHandler(PersonVo.class));
}
---------------
ps:MapHandler
3.
1. public Map getRegist() throws Exception {
2. QueryRunner queryRunner = new QueryRunner();
3. String sql = "select * from person where id = 2";
4. return (Map) queryRunner.query(getConnection(), sql,new MapHandler());
5. }
public Map getRegist() throws Exception {
QueryRunner queryRunner = new QueryRunner();
String sql = "select * from person where id = 2";
return (Map) queryRunner.query(getConnection(), sql,new MapHandler());
}
MapListHandler
4.
1. public List<Map> getRegist4() throws Exception {
2. QueryRunner queryRunner = new QueryRunner();
3. String sql = "select * from person";
4. return (List)queryRunner.query(getConnection(), sql,new MapListHandler());
5. }