4月7日

member.jsp文件
<%@ page import="po.ToTal" %>
<%@ page import="dao.TotalDaoImpl" %>
<%@ page import="java.util.List" %><%--
Created by IntelliJ IDEA.
User: mjj
Date: 2021/4/7
Time: 下午14:15
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
<meta charset="UTF-8">
<title>用户列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="./resource/css/font.css">
<link rel="stylesheet" href="./resource/css/xadmin.css">
<script src="./resource/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./resource/js/xadmin.js"></script>
<script type="text/javascript">
function clickIt(){
var p2=document.getElementById("t2").value;
location.href="People_Man.jsp?p="+p2;
}
</script>
</head>
<body>
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body ">
<form class="layui-form layui-col-space5">
<div class="layui-input-inline layui-show-xs-block">
<input type="text" name="username" placeholder="用户名" autocomplete="off" class="layui-input">
</div>

<div class="layui-input-inline lafite_search layui-show-xs-block">
<button class="layui-btn" lay-submit="" lay-filter="sreach">
查询</button>
</div>
</form>
</div>

<div class="layui-card-header">
<a class="layui-btn lafite_main_color" onclick="xadmin.open('新增用户','./addMan.jsp',1050,632)"><i class="layui-icon"></i>新增用户</a>
</div>
<%
ToTal toTal = new ToTal();
TotalDaoImpl dao = new TotalDaoImpl();
//2:获取从下面上一页下一页传来的参数p
String p2=request.getParameter("p");

//1:设置好第一页开始和一页有10条记录
int p=1;
int r=10;
//5:获取到返回的总页数,将每页的总记录数传进去
int count=dao.getCount(r);

//3:如果p2不为null且不为空,就转化为p
if(p2!=null && !p2.equals("")){
p=Integer.parseInt(p2);
}
//4:如果页数为负的那么就赋值为首页
if(p<=0){
p=1;
}
//6:控制后面的页数,如果大于总页数,将最后一页赋值为尾页即可
if(p>=count){
p=count;
}
//7:调用分页的方法进行分页操作
List<ToTal> list=dao.totalPage(p, r);
request.setAttribute("list",list);
request.setAttribute("tol1",toTal);
System.out.println(list);
%>
<div class="layui-card-body">
<table class="layui-table layui-form">

<thead>

<tr style="background: #F8E5E5;">
<th>会员名称</th>
<th>联系方式</th>
<th>会员等级</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:set var="bg" value="">
</c:set>
<c:forEach var="b" items="${list}" varStatus="i">
<c:if test="${i.index%2==0 }">
<c:set var="bg" value="#09F7F7"></c:set>
</c:if>
<c:if test="${i.index%2==1 }">
<c:set var="bg" value="#7755AA"></c:set>
</c:if>
<tr>
<td>${b.name}</td>
<td>${b.username}</td>
<td>${b.current_Org}</td>
<td>${b.department}</td>
<td>${b.pos}</td>
<td class="td-manage">
<a class="lafitewu_auditing" title="编辑" onclick="xadmin.open('编辑','./adduser.html',600,500)" href="javascript:;">
编辑
</a>
<a class="lafitewu_del lafitewu_margin_left_10" title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
删除
</a>

</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div class="layui-card-body ">
<div class="page">
<div align="center">
第<%=p %>/共<%=count %>页
<a href="People_Man.jsp?p=0">首页</a>
<a href="People_Man.jsp?p=<%=p-1 %>">上一页</a>
<a href="People_Man.jsp?p=<%=p+1 %>">下一页</a>
<a href="People_Man.jsp?p=<%=count%>">尾页</a>
<input type="text" size="2" id="t2">
<input type="button" value="go" onclick="clickIt()"/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>



member.dao文件
package dao;

import po.User;
import utlis.BaseDao;
import po.Member;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class MemberDao {
public boolean insertBasic(Member member){
String sql="insert into member(id,name,phone_num,root_value,address,sex,money) values(?,?,?,?,?,?,?)";

List<Object> list=new ArrayList<Object>();
list.add(member.getId());
list.add(member.getName());
list.add(member.getPhone_num());
list.add(member.getRoot_value());
list.add(member.getAddress());
list.add(member.getF_time());
list.add(member.getSex());
list.add(member.getMoney());



System.out.println(member);
boolean mark=BaseDao.addUpdateDelete(sql, list.toArray());
System.out.println(member);
if(mark){
return true;
}else{
return false;
}
}
public boolean inserttele(Member member) {
String sql="update People set phone_number=?,address=?,sex=? where Id=?";

List<Object> list=new ArrayList<Object>();
list.add(member.getPhone_num());
list.add(member.getAddress());
list.add(member.getSex());
System.out.println(member);
boolean mark=BaseDao.addUpdateDelete(sql, list.toArray());
System.out.println(member);
if(mark){
return true;
}else{
return false;
}
}
public int getCount(int record) {
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
//设置初始值为-1
int n=-1;
try {
con=BaseDao.getCon();//第一步连接数据库
//第二步书写sql语句
String sql="select count(*) from shop.member ";
ps=con.prepareStatement(sql);//第三步:预编译

//第四步执行sql
rs=ps.executeQuery();
if(rs.next()){
//获取第一条记录,因为查询count(1)就一条记录,获取即可,即总记录数
n=rs.getInt(1);
//将总记录数除以每页的总记录数然乎向上取整即可
n=(int)Math.ceil(1.0*n/record);
}

} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
//关闭资源,避免出现异常
BaseDao.close(con, ps, rs);
}

return n;
}
public Member getmember(Integer id) {
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
try {
con=BaseDao.getCon();//第一步连接数据库
String sql="select * from shop.member where shop.member.id=? ";
ps=con.prepareStatement(sql);//第二步:预编译
ps.setInt(1, id);
//第四步执行sql
rs=ps.executeQuery();
while(rs.next()){

Member member = new Member();
member.setId(rs.getInt("id"));
member.setName(rs.getString("name"));
member.setSex(rs.getString("sex"));
member.setPhone_num(rs.getInt("phone"));
member.setRoot_value(rs.getInt("root_value"));
member.setAddress(rs.getString("address"));
member.setF_time(rs.getString("F_time"));
member.setDays(rs.getInt("days"));
member.setMoney(rs.getInt("money"));
return member;
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
//关闭资源,避免出现异常
BaseDao.close(con, ps, rs);
}

return null;
}


public List<Member> peopPage(int page, int record) {
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
try {
con=BaseDao.getCon();//第一步连接数据库
//第二步书写sql语句
String sql="select * from shop.member limit ?,? ";
ps=con.prepareStatement(sql);//第三步:预编译
//第几页需要设置好是页数减一乘以每页的记录数即是第多少页
ps.setInt(1, (page-1)*record);
ps.setInt(2, record);

//第四步执行sql
rs=ps.executeQuery();
List<Member> list=new ArrayList<Member>();
while(rs.next()){
Member member = new Member();
member.setId(rs.getInt("id"));
member.setName(rs.getString("name"));
member.setSex(rs.getString("sex"));
member.setPhone_num(rs.getInt("phone"));
member.setRoot_value(rs.getInt("root_value"));
member.setAddress(rs.getString("address"));
member.setF_time(rs.getString("F_time"));
member.setDays(rs.getInt("days"));
member.setMoney(rs.getInt("money"));
list.add(member);
}
return list;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
//关闭资源,避免出现异常
BaseDao.close(con, ps, rs);
}

return null;
}

}

posted @ 2021-04-08 08:48  peogre  阅读(50)  评论(0编辑  收藏  举报