在GonggaoDao类中,以下代码实现了跳转的功能:

public List<Gonggao> selectGonggaoList() {
    String sql="select * from Gonggao where 1 = 1 order by id desc  ";
    List<Gonggao> list=null;
    try {
        list= runner.query(sql, new BeanListHandler<Gonggao>(Gonggao.class));//添加实体类的适配器进行类的反射
        return list;
    } catch (SQLException e) {//捕获异常
        throw new RuntimeException(e);//抛出运行异常
    }
}

public Gonggao findGonggaoById(String id) {
    try {//返回查询的信息
        return runner.query("select * from Gonggao where id=? ", new BeanHandler<Gonggao>(Gonggao.class),Integer.parseInt(id));
    } catch (SQLException e) {
        throw new RuntimeException(e);//抛出运行异常
    }
}

public void deleteGonggao(String id) {
    Integer ids = Integer.parseInt(id);
    try {//执行更改
        runner.update("delete from  Gonggao  where id=?",
                ids);
    } catch (SQLException e) {
        throw new RuntimeException(e);//抛出运行异常
    }
}

public void addGonggao(Gonggao Gonggao) {
    try {
        //执行插入sql
        runner.update("insert into Gonggao(title,content,ctime) values (?,?,?)",
                Gonggao.getTitle(),Gonggao.getContent(),Gonggao.getCtime());
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

public List<Gonggao> getGonggaoPage(int pageNum, int pageSize, Map map) {
    String sql="select * from Gonggao where 1 = 1 ";
    if(map.get("title") !=null && !map.get("title").toString().equals("")){
        sql+= " and title like  '%"+map.get("title").toString()+"%'";
    }
    sql+=" limit ?,? ";
    int startNo=(pageNum-1)*pageSize;
    List<Gonggao> list=null;
    try {
        list= runner.query(sql, new BeanListHandler<Gonggao>(Gonggao.class),new Object[] {startNo,pageSize});//添加实体类的适配器进行类的反射
        return list;
    } catch (SQLException e) {//捕获异常
        throw new RuntimeException(e);//抛出运行异常
    }
}

public int queryGonggaoCount(Map map) {
    String sql="select count(*) from Gonggao where 1 = 1 ";
    if(map.get("title") !=null && !map.get("title").toString().equals("")){
        sql+= " and title like  '%"+map.get("title").toString()+"%'";
    }
    try {
        Long count =  (Long) runner.query(sql, new ScalarHandler());
        //将long的类型转成int类型
        return count.intValue();
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

public void updateGonggao(Gonggao Gonggao) {
    try {//执行更改
        runner.update("update Gonggao set title=?,content=?where id=?",
                 Gonggao.getTitle(),Gonggao.getContent(),Gonggao.getId());
    } catch (SQLException e) {
        throw new RuntimeException(e);//抛出运行异常
    }
}

public List<Gonggao> selectAll() {
    String sql="select * from Gonggao ";
    List<Gonggao> list=null;
    try {
        list= runner.query(sql, new BeanListHandler<Gonggao>(Gonggao.class));//添加实体类的适配器进行类的反射
        return list;
    } catch (SQLException e) {//捕获异常
        throw new RuntimeException(e);//抛出运行异常
    }
}

这些方法实现了对公告信息的查询、添加、删除、更新等操作,可以在其他类中调用这些方法来实现跳转


原文地址: https://www.cveoy.top/t/topic/h8fj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录