@Repository("com.example.demo.dao.impl.SmpUserDaoImpl")
public class SmpUserDaoImpl implements SmpUserDao{
@Autowired
private JdbcTemplate jdbcTemplate; @Override
public SmpUserPo getByName(String name) {
SmpUserPo userPo = new SmpUserPo(); try {
String sql = "select `user_id`, `user_name`, `login_password`, `pay_password`, `create_date`, `update_date` from smp_user where user_name = ? ";
System.out.println(sql);
userPo = jdbcTemplate.queryForObject(sql,
new Object[]{name},
new BeanPropertyRowMapper<SmpUserPo>(SmpUserPo.class));
}catch (EmptyResultDataAccessException e){
System.out.println("用户no data");
return null;
}catch (Exception e){
System.out.println("exxc");
e.printStackTrace();
return null;
} return userPo;
} @Override
public void getAll() {
String sql = "select `user_id`, `user_name`, `login_password`, `pay_password`, `create_date`, `update_date` from smp_user where '1' = ? ";
System.out.println(sql);
SmpUserPo userPo = new SmpUserPo();
jdbcTemplate.query(sql,new Object[]{"1"},new ResultSetExtractor(){
@Override
public Object extractData(ResultSet rs) throws SQLException,DataAccessException {
while(rs.next()) {
userPo.setUserId(rs.getLong("user_id"));
userPo.setUserName(rs.getString("user_name"));
userPo.setLoginPassword(rs.getString("login_password"));
userPo.setPayPassword(rs.getString("pay_password"));
userPo.setCreateDate(rs.getLong("create_date"));
userPo.setUpdateDate(rs.getLong("update_date")); System.out.println(userPo.getUserName());
}
return null;
}
}); } }

spring jdbc 记录的更多相关文章

  1. Spring学习记录(十四)---JDBC基本操作

    先看一些定义: 在Spring JDBC模块中,所有的类可以被分到四个单独的包:1.core即核心包,它包含了JDBC的核心功能.此包内有很多重要的类,包括:JdbcTemplate类.SimpleJ ...

  2. spring jdbc获取插入记录的主键id

    在JDBC3.0规范中,当新增记录时,允许将数据库自动产生的主键值绑定到Statement或PreparedStatement中.使用Statement时,可以通过以下方法绑定主键值: int exe ...

  3. spring jdbc 查询结果返回对象、对象列表

    首先,需要了解spring jdbc查询时,有三种回调方式来处理查询的结果集.可以参考 使用spring的JdbcTemplate进行查询的三种回调方式的比较,写得还不错. 1.返回对象(queryF ...

  4. Spring JDBC实现查询

    1 db.properties jdbc.user=root jdbc.password=920614 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbc ...

  5. Spring学习进阶(四) Spring JDBC

    Spring JDBC是Spring所提供的持久层技术.主要目的是降低使用JDBC API的门槛,以一种更直接,更简洁的方式使用JDBC API.在Spring JDBC里用户仅需要做哪些比不可少的事 ...

  6. Spring JDBC常用方法详细示例

    Spring JDBC使用简单,代码简洁明了,非常适合快速开发的小型项目.下面对开发中常用的增删改查等方法逐一示例说明使用方法 1 环境准备 启动MySQL, 创建一个名为test的数据库 创建Mav ...

  7. Spring JDBC 访问MSSQL

    在Spring中对底层的JDBC做了浅层的封装即JdbcTemplate,在访问数据库的DAO层完全可以使用JdbcTemplate完成任何数据访问的操作,接下来我们重点说说Spring JDBC对S ...

  8. Spring JDBC 随笔

    Spring 框架,借助 JdbcTemplate 类来简化 java 访问 database. 完成一个增查改删(CRUD)的基本功能,借助下面 5 个角色来共同来完成. 1. object cla ...

  9. 开涛spring3(7.5) - 对JDBC的支持 之 7.5 集成Spring JDBC及最佳实践

    7.5 集成Spring JDBC及最佳实践 大多数情况下Spring JDBC都是与IOC容器一起使用.通过配置方式使用Spring JDBC. 而且大部分时间都是使用JdbcTemplate类(或 ...

随机推荐

  1. 【java】之cron表达式

    秒(~) 分钟(~) 小时(~) 天(月)(~,但是你需要考虑你月的天数) 月(~) 天(星期)(~ =SUN 或 SUN,MON,TUE,WED,THU,FRI,SAT) .年份(-) 其中每个元素 ...

  2. 解决Ubuntn安装中文语言包却不能切换

    记一次奇葩的经历吧,第一次在VM中安装Ubuntn16.04安装完成后的确出现了语言包安装提示,就这样毫无压力的一直用着中文版的Ubuntn. 习惯了一段时间后第二次安装一样的安装方式却始终是英文界面 ...

  3. Python发送微信消息

    针对此 需要安装itchat第三方模块 采用pip安装就可以了   pip install itchat import itchatimport time#引入时间函数进行测试time_format= ...

  4. Angular2中使用ngx-translate进行国际化

    转自 https://blog.csdn.net/u014291497/article/details/61233033 相较于angularjs中的ng-translate, angular2也有适 ...

  5. orcal - 单行函数

    虚拟表:dual 转大写 select UPPER('hellow') from dual; 转小写 select lower(ename) from emp; cmd 输入数据 select * f ...

  6. python至winreg模块

    _winreg模块在python3中已经改名了 https://blog.csdn.net/zhangxiaoyang0/article/details/72236305?fps=1&loca ...

  7. 2Linux常用命令-Liunu就该这么学

    常用系统工作命令 1.echo 用于在终端输出字符串或变量提取后的值,格式为“echo [字符串 | $变量]” 2.date date "+%Y-%m-%d %H:%M:%S" ...

  8. tp5框架中jquery+ajax分页

    jaxa分页,点击按钮直接替换数据, //php代码$page=Request::instance()->param("page"); $page = empty($page ...

  9. 编织织物的knit course direction and knit wale direction

    来自:http://www.definetextile.com/2013/04/course-wale.html

  10. Android中使用commons-codec-1.6.jar 进行Base64编解码出现的问题

    编码时出现异常: java.lang.NoSuchMethodError: No static method encodeBase64String([B)Ljava/lang/String; in c ...