package com.spring5.dao;
import com.spring5.test.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.Arrays;
import java.util.List;
@Repository
public class BookDaoImpl implements BookDao {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void add(Book book) {
//1 创建 sql 语句
String sql = "insert into t_book values(?,?,?)";
//2 调用方法实现
Object[] args = {book.getUserId(), book.getUsername(),
book.getUstatus()};
int update = jdbcTemplate.update(sql, args);
System.out.println(update);
}
@Override
public void updateBook(Book book) {
String sql = "update t_book set username=?,ustatus=? where user_id=?";
Object[] args = {book.getUsername(), book.getUstatus(),book.getUserId()};
int update = jdbcTemplate.update(sql, args);
System.out.println(update);
}
@Override
public void delete(String id) {
String sql = "delete from t_book where user_id=?";
int update = jdbcTemplate.update(sql, id);
System.out.println(update);
}
//查询返回集合
@Override
public List<Book> findAllBook() {
String sql = "select * from t_book";
//调用方法
List<Book> bookList = jdbcTemplate.query(sql, new
BeanPropertyRowMapper<Book>(Book.class));
for (Book data : bookList) {
System.out.println(data.getUserId()+"****"+data.getUsername()+"***********"+data.getUstatus());
}
return bookList;
}
//批量添加
@Override
public void batchAddBook(List<Object[]> batchArgs) {
String sql = "insert into t_book values(?,?,?)";
int[] ints = jdbcTemplate.batchUpdate(sql, batchArgs);
System.out.println(Arrays.toString(ints));
}
//批量修改
@Override
public void batchUpdateBook(List<Object[]> batchArgs) {
String sql = "update t_book set username=?,ustatus=? where user_id=?";
int[] ints = jdbcTemplate.batchUpdate(sql, batchArgs);
System.out.println(Arrays.toString(ints));
}
//批量删除
@Override
public void batchDeleteBook(List<Object[]> batchArgs) {
String sql = "delete from t_book where user_id=?";
int[] ints = jdbcTemplate.batchUpdate(sql, batchArgs);
System.out.println(Arrays.toString(ints));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
spring5_demo.zip (76个子文件)
spring5_demo
log
test.log 0B
src
com
spring5
dao
BookDaoImpl.java 3KB
BookDao.java 446B
config
TxConfig.java 1KB
test
TestBook.java 2KB
Book.java 609B
service
BookService.java 977B
bean.xml 2KB
t_book.sql 1KB
.idea
uiDesigner.xml 9KB
misc.xml 411B
vcs.xml 173B
description.html 97B
modules.xml 277B
encodings.xml 196B
compiler.xml 734B
workspace.xml 43KB
inspectionProfiles
Project_Default.xml 591B
out
production
spring5_demo5
com
atguigu
spring5
dao
BookDao.class 624B
BookDaoImpl.class 4KB
test
TestBook.class 1KB
service
BookService.class 2KB
entity
Book.class 1KB
bean1.xml 1KB
spring5_demo4
META-INF
spring5_demo4.kotlin_module 16B
com
atguigu
spring5
UserDaoProxy.class 1KB
UserDao.class 195B
UserDaoImpl.class 799B
test
TestAop.class 1KB
aopxml
BookProxy.class 536B
Book.class 519B
aopanno
User.class 627B
UserProxy.class 2KB
PersonProxy.class 867B
JDKProxy.class 1KB
bean1.xml 927B
bean2.xml 1KB
spring5_demo3
com
atguigu
spring5
dao
UserDao.class 139B
UserDaoImpl.class 683B
config
SpringConfig.class 510B
service
UserService.class 1KB
testdemo
TestSpring5Demo1.class 1KB
spring5_demo2
META-INF
spring5_demo2.kotlin_module 16B
bean4.xml 866B
bean1.xml 2KB
bean5.xml 1KB
bean2.xml 981B
bean3.xml 643B
spring5_txdemo1
com
atguigu
spring5
dao
BookDao.class 513B
BookDaoImpl.class 3KB
config
TxConfig.class 1KB
test
TestBook.class 1KB
Book.class 928B
service
BookService.class 2KB
bean.xml 2KB
lib
log4j-api-2.11.2.jar 260KB
spring-expression-5.2.6.RELEASE.jar 276KB
spring-beans-5.2.6.RELEASE.jar 670KB
spring-test-5.2.6.RELEASE.jar 669KB
mysql-connector-java-5.1.7-bin.jar 693KB
slf4j-api-1.7.30.jar 41KB
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar 1.57MB
spring-orm-5.2.6.RELEASE.jar 196KB
spring-aspects-5.2.6.RELEASE.jar 46KB
spring-jdbc-5.2.6.RELEASE.jar 398KB
commons-logging-1.1.1.jar 59KB
com.springsource.org.aopalliance-1.0.0.jar 5KB
spring-aop-5.2.6.RELEASE.jar 364KB
spring-tx-5.2.6.RELEASE.jar 307KB
druid-1.1.9.jar 2.59MB
log4j-core-2.11.2.jar 1.55MB
com.springsource.net.sf.cglib-2.2.0.jar 319KB
spring-core-5.2.6.RELEASE.jar 1.38MB
log4j-slf4j-impl-2.11.2.jar 23KB
spring-context-5.2.6.RELEASE.jar 1.17MB
spring5_txdemo1.iml 6KB
共 76 条
- 1
刘大哥的博客
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 12Cr1MoV钢主蒸汽管道焊接工艺.pdf
- 12Cr1MoV小径管焊接操作工艺 - .pdf
- 12Cr1MoV异种钢焊接温度场的数值模拟.pdf
- 12Cr2Mo1R珠光体耐热钢的焊接 - .pdf
- 13MnNiMoNbR复合银板焊接裂纹的修复.pdf
- 12MnNiVR钢板焊接裂纹敏感性的试验研究.pdf
- 12MnNiVR钢热处理性能及大热输入焊接韧性.pdf
- 13MnNiMoNbR钢焊接工艺研究.pdf
- 13MnNiMoNbR压力容器高强钢焊接工艺研究.pdf
- 14Cr1MoR新钢种的焊接试验研究.pdf
- 14Cr1MoR-I-0Cr18Ni10Ti复合钢板的焊接 - .pdf
- 13焊接空心球节点的承载能力分析.pdf
- 14CrMoR耐热钢压力容器的埋弧焊焊接工艺应用 - .pdf
- 14CrlMoR+0Crl8Nil0Ti复合钢板焊接.pdf
- 14YTJ108 复合保温钢筋焊接网架混凝土墙(CL建筑体系)构造.pdf
- 15×104_m3双盘浮顶油罐底板焊接工艺.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0