src/edu/school/dao/impl/LeaveDaoImpl.java
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package edu.school.dao.impl;
import edu.school.dao.LeaveDao;
import edu.school.entity.Leave;
import edu.school.entity.PageTool;
import edu.school.entity.Student;
import edu.school.utils.C3p0Utils;
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.SQLException;
import java.util.ArrayList;
import java.util.List;
public class LeaveDaoImpl implements LeaveDao {
private QueryRunner runner=new QueryRunner(C3p0Utils.getDs());
//学生查询自己请假信息
@Override
public List<Leave> getLeaveByStuId(Integer stuId, PageTool pageTool) {
String sql="select * from leaves where stu_id=? limit ?,?";
List<Leave> list=null;
try {
list=runner.query(sql,new BeanListHandler<Leave>(Leave.class),stuId,pageTool.getStartIndex(),pageTool.getPageSize());
return list;
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
//查询请假信息数量
@Override
public int queryLeaveCountByStuId(Integer stuId) {
String sql="select count(*) from leaves where stu_id = ?";
try {
Long count = (Long) runner.query(sql, new ScalarHandler(),stuId);
//将long的类型转成int类型
return count.intValue();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
//添加请假信息
@Override
public int addLeave(Leave leave) {
try {
//执行插入sql
runner.update("insert into leaves(stu_id,startDate ,endDate,flag,reason) values (?,?,?,?,?)",
leave.getStuId(),leave.getStartDate(),leave.getEndDate(),leave.getFlag(),leave.getReason());
} catch (SQLException e) {
throw new RuntimeException(e);
}
return 1;
后面还有 86 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。