2016 - 2025

感恩一路有你

jdbctemplate连接池 SpringjdbcgetJdbcTemplate()queryForObject如何返回对象?

浏览量:2290 时间:2021-03-15 04:28:53 作者:admin

SpringjdbcgetJdbcTemplate()queryForObject如何返回对象?

public User IsQueryOne(String id)抛出异常{try{User User=(User)this.getJdbcTemplate().queryForObject(“select*from test where id=”id用户.class)return user}catch(异常e){public Object mapRow(ResultSet rs,int value)抛出SQLException{user user=new user()用户.setId(新整数(rs.getInt公司(“id”))user.setUsername( rs.getString字符串(“用户名”)用户设置( rs.getString字符串(“age”)return user}},然后直接返回public user isqueryone(string ID)抛出runtimeException{string SQL=“select*from test where ID=”ID//现在您可以看到类userrowmapper返回(user)有多方便了this.getJdbcTemplate(). Queryforobject(SQL,newuserrowmapper())}我刚刚玩了AOP。。。否则Acegi会很难。。。啊~~无聊。。。。

jdbctemplate连接池 回滚什么意思 什么是回滚

版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。