package main.demo.dao.impl;
import main.demo.Entity.Emp;
import main.demo.dao.EmpDao;
import main.demo.mapper.RowMapper;
import main.demo.mapper.impl.EmpRowMapper;
import main.demo.utile.DBUtil;
import main.demo.utile.DaoUtil;
import main.demo.utile.DateUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class EmpDaoImpl implements EmpDao {
private static QueryRunner queryRunner = new QueryRunner(DBUtil.getDataSource());
private DaoUtil daoUtil = new DaoUtil();
private RowMapper rowMapper = new EmpRowMapper();
@Override
public int insertEmp(Emp emp) throws SQLException, ParseException {
StringBuilder stringBuilder = new StringBuilder("insert into emp (name,salary,joinDate,job,deptNo) values");
stringBuilder.append("(?,?,?,?,?)");
Connection connection = DBUtil.getConnection();
// String.valueOf(stringBuilder)
// int resultSet = DaoUtil.commandUpdate(String.valueOf(stringBuilder),emp.getName(),emp.getSalary(),
// DateUtil.changeUtilDateToSqlDate(emp.getJoinDate()),emp.getJob(),emp.getDeptNo());
// //使用commons-dbutils的jar包来时现增删查改
int resultSet1 = queryRunner.update(stringBuilder.toString(), emp.getName(), emp.getSalary(),
DateUtil.changeUtilDateToSqlDate(emp.getJoinDate()), emp.getJob(), emp.getDeptNo());
// PreparedStatement preparedStatement = connection.prepareStatement(stringBuilder.toString());
// preparedStatement.setString(1,emp.getName());
// preparedStatement.setFloat(2,emp.getSalary());
// preparedStatement.setDate(3, DateUtil.changeUtilDateToSqlDate(emp.getJoinDate()));
// preparedStatement.setString(4,emp.getJob());
// preparedStatement.setInt(5,emp.getDeptNo());
// int resultSet = preparedStatement.executeUpdate();
return resultSet1;
}
@Override
public List query() throws SQLException {
StringBuilder stringBuilder = new StringBuilder("select empNo,name,salary,joinDate,job,deptNo from emp ");
List<Emp> list = daoUtil.commandQuery(String.valueOf(stringBuilder), rowMapper,null);
// queryRunner.query(String.valueOf(stringBuilder),new ResourceBundle(Emp)<>)
List<Emp> query = queryRunner.query(String.valueOf(stringBuilder), new BeanListHandler<Emp>(Emp.class));
return query;
}
@Override
public Emp findByname(String name) throws SQLException {
StringBuilder stringBuilder = new StringBuilder("select empNo,name,salary,joinDate,job,deptNo from emp where name = ?");
Emp query = queryRunner.query(String.valueOf(stringBuilder), new BeanHandler<Emp>(Emp.class),name);
return query;
}
@Override
public float findSinger(Object o) throws SQLException {
StringBuilder stringBuilder = new StringBuilder("select max(salary) from emp");
float salary = queryRunner.query(String.valueOf(stringBuilder), new ScalarHandler<>());
return salary;
}
@Override
public List findNumPage(int t) throws SQLException {
StringBuilder stringBuilder = new StringBuilder("select empNo,name,salary,joinDate,job,deptNo from emp limit ?,?");
// List<Emp> list = daoUtil.commandQuery(String.valueOf(stringBuilder), rowMapper,(t-1)*2,2);
List<Emp> query = queryRunner.query(String.valueOf(stringBuilder), new BeanListHandler<Emp>(Emp.class),(t-1)*2,2);
return query;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java封装model 和 controller之间的数据和控制的三层架构
共75个文件
java:25个
class:25个
xml:11个
需积分: 5 0 下载量 77 浏览量
2024-08-13
20:17:40
上传
评论
收藏 113KB ZIP 举报
温馨提示
包括dao层和entity,service 和view ,util 层(包括threadLocal和线程池)
资源推荐
资源详情
资源评论
收起资源包目录
day-2024-8-6.zip (75个子文件)
day-2024-8-6
day-2024-8-6.iml 671B
src
db.properties 323B
main
demo
mapper
impl
EmpRowMapper.java 671B
RowMapper.java 182B
servies
UserService.java 129B
impl
EmpServiceImpl.java 2KB
AccountServiesImpl.java 1KB
UserServiesImpl.java 643B
AccountServies.java 147B
EmpService.java 275B
dao
UserDao.java 135B
AccountDao.java 260B
impl
UserDaoImpl.java 1KB
EmpDaoImpl.java 4KB
AccountDaoImpl.java 2KB
EmpDao.java 442B
view
Test5.java 111B
Test2.java 404B
Test4.java 869B
Test3.java 1KB
Test1.java 788B
utile
DateUtil.java 912B
DaoUtil.java 1KB
DBUtil.java 3KB
hello.html 398B
Entity
Emp.java 2KB
User.java 2KB
Account.java 1KB
demo1
out
production
day-2024-8-6
db.properties 323B
main
demo
mapper
RowMapper.class 325B
impl
EmpRowMapper.class 2KB
servies
AccountServies.class 212B
UserService.class 166B
impl
UserServiesImpl.class 1KB
AccountServiesImpl.class 1KB
EmpServiceImpl.class 2KB
EmpService.class 558B
dao
UserDao.class 189B
AccountDao.class 239B
EmpDao.class 618B
impl
EmpDaoImpl.class 4KB
AccountDaoImpl.class 2KB
UserDaoImpl.class 2KB
view
Test5.class 388B
Test3.class 2KB
Test2.class 1KB
Test4.class 2KB
Test1.class 1KB
utile
DateUtil.class 1KB
DaoUtil.class 2KB
DBUtil.class 2KB
hello.html 141B
Entity
Account.class 2KB
User.class 2KB
Emp.class 3KB
.idea
dataSources
59a9ae55-8787-4366-9950-875a8f0b4012
storage_v2
_src_
schema
performance_schema.kIw0nw.meta 76B
ycl_db2.V2Tgrw.meta 10B
sys.zb4BAA.meta 61B
information_schema.FNRwLQ.meta 76B
mysql.osA4Bg.meta 63B
ycl_db2.V2Tgrw.zip 733B
sys.zb4BAA.zip 260KB
59a9ae55-8787-4366-9950-875a8f0b4012.xml 165KB
dataSources.local.xml 1002B
uiDesigner.xml 9KB
sqldialects.xml 363B
libraries
druid_1_1_5.xml 234B
commons_dbutils_1_7.xml 250B
mysql_connector_java_5_1_25_bin.xml 270B
workspace.xml 8KB
misc.xml 275B
dataSources.xml 530B
modules.xml 271B
.gitignore 184B
.gitignore 344B
共 75 条
- 1
资源评论
keepruning
- 粉丝: 41
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功