spring jdbc 记录
@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 记录的更多相关文章
- Spring学习记录(十四)---JDBC基本操作
先看一些定义: 在Spring JDBC模块中,所有的类可以被分到四个单独的包:1.core即核心包,它包含了JDBC的核心功能.此包内有很多重要的类,包括:JdbcTemplate类.SimpleJ ...
- spring jdbc获取插入记录的主键id
在JDBC3.0规范中,当新增记录时,允许将数据库自动产生的主键值绑定到Statement或PreparedStatement中.使用Statement时,可以通过以下方法绑定主键值: int exe ...
- spring jdbc 查询结果返回对象、对象列表
首先,需要了解spring jdbc查询时,有三种回调方式来处理查询的结果集.可以参考 使用spring的JdbcTemplate进行查询的三种回调方式的比较,写得还不错. 1.返回对象(queryF ...
- Spring JDBC实现查询
1 db.properties jdbc.user=root jdbc.password=920614 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbc ...
- Spring学习进阶(四) Spring JDBC
Spring JDBC是Spring所提供的持久层技术.主要目的是降低使用JDBC API的门槛,以一种更直接,更简洁的方式使用JDBC API.在Spring JDBC里用户仅需要做哪些比不可少的事 ...
- Spring JDBC常用方法详细示例
Spring JDBC使用简单,代码简洁明了,非常适合快速开发的小型项目.下面对开发中常用的增删改查等方法逐一示例说明使用方法 1 环境准备 启动MySQL, 创建一个名为test的数据库 创建Mav ...
- Spring JDBC 访问MSSQL
在Spring中对底层的JDBC做了浅层的封装即JdbcTemplate,在访问数据库的DAO层完全可以使用JdbcTemplate完成任何数据访问的操作,接下来我们重点说说Spring JDBC对S ...
- Spring JDBC 随笔
Spring 框架,借助 JdbcTemplate 类来简化 java 访问 database. 完成一个增查改删(CRUD)的基本功能,借助下面 5 个角色来共同来完成. 1. object cla ...
- 开涛spring3(7.5) - 对JDBC的支持 之 7.5 集成Spring JDBC及最佳实践
7.5 集成Spring JDBC及最佳实践 大多数情况下Spring JDBC都是与IOC容器一起使用.通过配置方式使用Spring JDBC. 而且大部分时间都是使用JdbcTemplate类(或 ...
随机推荐
- css零碎知识点小结
1.单行文字溢出显示省略号: div{ width: 200px; overflow: hidden; text-overflow:ellipsis; white-space: nowrap; } 2 ...
- 动态规划经典——最长公共子序列问题 (LCS)和最长公共子串问题
一.最长公共子序列问题(LCS问题) 给定两个字符串A和B,长度分别为m和n,要求找出它们最长的公共子序列,并返回其长度.例如: A = "HelloWorld" B = & ...
- python3学习笔记四(列表1)
参考http://www.runoob.com/python3/python3-list.html 序列 python包含6种内建的序列:列表,元组,字符串,Unicode字符串,buffer对象和x ...
- Ubuntu16.04配置Eclipse开发OpenCV
系统环境 Ubuntu 16.04; OpenCV2.4.13; Eclipse neon for C++ 配置步骤 1.配置JDK,此处配置的是JDK1.8,详见<Ubuntu 16.04 ...
- access数据库编号转换成统一3位数长度方法,不足3位前面补零
select C_CUN+Format(Val(NZ(C_LB)),"000") from LBM 这条SQL只能在access数据库中执行,因为sql不支持NZ函数,而且c_lb ...
- 实验二:Linux下Xen环境的安装
实验名称: Linux下Xen环境的安装(centOS7) 实验环境: 本次实验基本是在centOS7的环境下完成,系统内核和系统版本如下: 实验要求: 为centOS7的环境下安装Xen的平台,能够 ...
- Hibernate工作原理及为什么要用?
1.原理: 1.读取并解析配置文件 new Configuration().configure()2.读取并解析映射信息,创建SessionFactory sf=buildSessionF ...
- python中class的序列化和反序列化
对于类的序列化:将类的成员变量名和数据作为一对键值对存储在物理内存中,例如 class A(object): def __init__(self): self.a = o self.b = 1 sel ...
- 【Linux】【Selenium】安装Chrome和ChromeDriver的配置
转自:https://www.cnblogs.com/longronglang/p/8078898.html 1.安装chrome sudo apt-get install libxss1 libap ...
- 一个简单SpringBoot例子
一:为什么使用springBoot: 有利于开发(整合框架,例如整合了springMVC,Mybatis等框架); 启动无需配置tomcat(java应用程序运行,实际以jar包运行),内置tomca ...