码迷,mamicode.com
首页 > 移动开发 > 详细

关于数据库查询new BeanPropertyRowMapper

时间:2020-05-11 21:42:17      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:select   row   username   print   get   err   toe   this   关于   

//bean类必须有无参构造,不然new BeanPropertyRowMapper<bean>(bean.class)不会把数据转为bean对象

@Test
public void test3() throws PropertyVetoException { // List<bean> query = jdbcTemplate.query("select * from jiang", new BeanPropertyRowMapper<>(bean.class)); List<bean> query = jdbcTemplate.query("select * from jiang",new BeanPropertyRowMapper<bean>(bean.class)); System.out.println(query); }
package com.jiang;

public class bean {
    private String username;
    private String password;

    public bean() {
    }

    public bean(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "bean{" +
                "username=‘" + username + ‘\‘‘ +
                ", password=‘" + password + ‘\‘‘ +
                ‘}‘;
    }
}

 

关于数据库查询new BeanPropertyRowMapper

标签:select   row   username   print   get   err   toe   this   关于   

原文地址:https://www.cnblogs.com/jiangzishun/p/12872087.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!