spring中JdbcTemplate的使用

//保存
template.execute("insert into account(name,money) values('lisi',1500)");

//更新
template.update("update account set name = ?,money = ? where id = ?","lisan",1300f,9);

 //删除
template.update("delete from account where id = ?",9);

//查询所有	使用query方法 new BeanPropertyRowMapper<Account>(Account.class) 返回值为一个列表
List<Account> accounts = template.query("select * from account where money > ?", new BeanPropertyRowMapper<Account>(Account.class), 1000f);
for (Account account : accounts) {
    System.out.println(account);
}

//查询一个对象  使用queryFroObject方法,new BeanPropertyRowMapper<Account>(Account.class) 返回值为一个对象
Account account = template.queryForObject("select * from account where id = ?",new BeanPropertyRowMapper<Account>(Account.class),1);
System.out.println(account);

//聚合函数  queryForObject方法,Integer.class  返回值为一个Integer类型的数字
Integer count = template.queryForObject("select count(*) from account where money > ?", Integer.class, 1000f);
        System.out.println(count);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值