Jsp显示数据库所有数据

这里使用QueryRunner查询

  @Override
    public List<User> allUser() throws SQLException {
        String sql ="select * from `user`";
        List<User> query = Qr.qr().query(sql, new BeanListHandler<User>(User.class));
        System.out.println(query);
        return query;
    }

jsp页面

<%-- 导入jstl--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    UserDaoImpl userDao = new UserDaoImpl();
    try {
        request.setAttribute("list", userDao.allUser());
    } catch (SQLException e) {
        e.printStackTrace();
    }
%>

<c:forEach begin="0" end="${list.size()-1}" var="i">
    <table>
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>昵称</th>
            <th>密码</th>
            <th>性别</th>
            <th>生日</th>
            <th>邮箱</th>

        </tr>
        <tr>
            <td> ${list[i].uid}</td>
            <td> ${list[i].username}</td>
            <td> ${list[i].name}</td>
            <td> ${list[i].password}</td>
            <td> ${list[i].sex}</td>
            <td> ${list[i].birthday}</td>
            <td> ${list[i].email}</td>
        </tr>
    </table>
</c:forEach>
<c:forEach var="u" items="${list}">
    <table>
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>昵称</th>
            <th>密码</th>
            <th>性别</th>
            <th>生日</th>
            <th>邮箱</th>

        </tr>
        <tr>
            <td> ${u.uid}</td>
            <td> ${u.username}</td>
            <td> ${u.name}</td>
            <td> ${u.password}</td>
            <td> ${u.sex}</td>
            <td> ${u.birthday}</td>
            <td> ${u.email}</td>
        </tr>
    </table>
</c:forEach>
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值