JSP显示新闻

一、建表并初始化数据

 

 

 二、登陆

2.1 登陆失败提示

 

 

 

 

 

 2.2 登陆成功显示新闻列表

public class NewsMapperImpl implements NewsMapper {
    @Override
    public List<News> findAllNewsHref() {
        Connection conn = null;
        Statement statement = null;
        ResultSet rs = null;
        List<News> news = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            conn = DBUtil.getConnection();
            statement = conn.createStatement();

            String sql = "select * from news";
            rs = statement.executeQuery(sql);
            while (rs.next()) {
                News nw = new News(
                        rs.getInt(1),
                        rs.getString(2),
                        rs.getString(3),
                        rs.getString(4),
                        sdf.parse(rs.getString(5))
                );
                news.add(nw);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return news;
    }
}

 

 2.2.1 service层

 

 

 

 2.2.2 dao层:

 

2.2.3 controller层

 

 

 2.2.4 jsp界面

 

 

 效果:

 

 码云地址:https://gitee.com/chaserff/J2EE.git

posted @ 2020-06-15 13:31  chaserFF  阅读(165)  评论(0编辑  收藏  举报