宿舍管理系统简单的增删改查
程序员文章站
2022-05-08 14:44:09
...
本系统仅为学习资料,代码太多只能展示部分,如果有不对或不足的地方请告知,必定虚心接受并加以改正:
系统用layui做前端,servlet做后端写的,数据库MySQL
首先进入登录页面,本系统分为三个登录状态,系统管理员,宿舍管理员与学生,系统管理员能够管理宿舍管理员信息与学生信息,同时指定宿舍管理员成为某个公寓的管理员,宿舍管理员负责学生迁移迁出情况与缺寝情况,下面是登录页面:
选择系统管理员输入账号密码登录进系统:
进入系统后显示宿舍管理员页面,点击查看查看宿管信息:
点击表中信息,出来可编辑的标志:
更改完信息后点击编辑完成更新:
点击删除出现弹框并提示“是否删除此条信息”,点击确定成功删除信息:
点击添加信息弹出弹框后填写信息并提交成功添加数据:
学生信息操作与宿管信息操作同理,下面是部分代码,首先是页面:
<div class="layui-layout layui-layout-admin kit-layout-admin">
<div class="layui-header">
<div class="layui-logo">后台管理</div>
<div class="layui-logo kit-logo-mobile">K</div>
<ul class="layui-nav layui-layout-left kit-nav">
<li class="layui-nav-item"><a href="javascript:;">控制台</a></li>
<li class="layui-nav-item"><a href="javascript:;">商品管理</a></li>
<li class="layui-nav-item"><a href="javascript:;" id="pay"><i class="fa fa-gratipay" aria-hidden="true"></i> 捐赠我</a></li>
<li class="layui-nav-item">
<a href="javascript:;">其它系统</a>
<dl class="layui-nav-child">
<dd><a href="javascript:;">邮件管理</a></dd>
<dd><a href="javascript:;">消息管理</a></dd>
<dd><a href="javascript:;">授权管理</a></dd>
</dl>
</li>
</ul>
<ul class="layui-nav layui-layout-right kit-nav">
<li class="layui-nav-item">
<a href="javascript:;">
<i class="layui-icon"></i> 皮肤</a>
</a>
<dl class="layui-nav-child skin">
<dd><a href="javascript:;" data-skin="default" style="color:#393D49;"><i class="layui-icon"></i> 默认</a></dd>
<dd><a href="javascript:;" data-skin="orange" style="color:#ff6700;"><i class="layui-icon"></i> 橘子橙</a></dd>
<dd><a href="javascript:;" data-skin="green" style="color:#00a65a;"><i class="layui-icon"></i> 原谅绿</a></dd>
<dd><a href="javascript:;" data-skin="pink" style="color:#FA6086;"><i class="layui-icon"></i> 少女粉</a></dd>
<dd><a href="javascript:;" data-skin="blue.1" style="color:#00c0ef;"><i class="layui-icon"></i> 天空蓝</a></dd>
<dd><a href="javascript:;" data-skin="red" style="color:#dd4b39;"><i class="layui-icon"></i> 枫叶红</a></dd>
</dl>
</li>
<li class="layui-nav-item">
<a href="javascript:;">
<img src="images/2.jpg" class="layui-nav-img">${t.admin_Name}
</a>
<dl class="layui-nav-child">
<dd><a href="javascript:;" kit-target data-options="{url:'userbasic',icon:'',title:'基本资料',id:'966'}"><span>基本资料</span></a></dd>
<dd><a href="javascript:;">安全设置</a></dd>
</dl>
</li>
<li class="layui-nav-item"><a href="zhuxiao"><i class="fa fa-sign-out" aria-hidden="true"></i> 注销</a></li>
</ul>
</div>
<div class="layui-side layui-bg-black kit-side">
<div class="layui-side-scroll">
<div class="kit-side-fold"><i class="fa fa-navicon" aria-hidden="true"></i></div>
<!-- 左侧导航区域(可配合layui已有的垂直导航) -->
<ul class="layui-nav layui-nav-tree" lay-filter="kitNavbar" kit-navbar>
<% if(session.getAttribute("type").toString().equals("1")){ %>
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;"><i class="fa fa-plug" aria-hidden="true"></i><span>公寓管理</span></a>
<dl class="layui-nav-child">
<dd>
<a href="javascript:;" kit-target data-options="{url:'main01.jsp',icon:'',title:'订单',id:'1',page:1,limit:10}">
<i class="layui-icon"></i><span>公寓管理员管理</span></a>
</dd>
<dd>
<a href="javascript:;" data-url="buildManager.jsp" data-icon="fa-user" data-title="公寓管理" kit-target data-id='2'><i class="fa fa-user" aria-hidden="true"></i><span>公寓管理</span></a>
</dd>
</dl>
</li>
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;"><i class="fa fa-plug" aria-hidden="true"></i><span>宿舍管理</span></a>
<dl class="layui-nav-child">
<dd>
<a href="javascript:;" kit-target data-options="{url:'main.jsp',icon:'',title:'订单',id:'1'}">
<i class="layui-icon"></i><span>宿舍管理</span></a>
</dd>
</dl>
</li>
<li class="layui-nav-item layui-nav-itemed">
<a href="javascript:;"><i class="fa fa-plug" aria-hidden="true"></i><span>学生管理</span></a>
<dl class="layui-nav-child">
<dd><a href="javascript:;" kit-target data-options="{url:'main02.jsp',icon:'',title:'Navbar',id:'6'}"><i class="layui-icon"></i><span>学生管理</span></a></dd>
<dd><a href="javascript:;" kit-target data-options="{url:'CheckIN.jsp',icon:'',title:'TAB',id:'7'}"><i class="layui-icon"></i><span>学生入住登记</span></a></dd>
<dd><a href="javascript:;" kit-target data-options="{url:'studentManage.jsp',icon:'',title:'App',id:'8'}"><i class="layui-icon"></i><span>学生迁出登记</span></a></dd>
<dd><a href="javascript:;" kit-target data-options="{url:'out.jsp',icon:'',title:'App',id:'8'}"><i class="layui-icon"></i><span>学生迁出记录</span></a></dd>
<dd><a href="javascript:;" kit-target data-options="{url:'updPwd.jsp',icon:'',title:'App',id:'8'}"><i class="layui-icon"></i><span>修改密码</span></a></dd>
</dl>
</li>
<%} %>
</ul>
</div>
</div>
<div class="layui-body" id="container">
<!-- 内容主体区域 -->
<div style="padding: 15px;"><i class="layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i> 请稍等...</div>
</div>
<div class="layui-footer">
<!-- 底部固定区域 -->
2017 ©
<a href="http://kit.zhengjinfan.cn/">kit.zhengjinfan.cn/</a> MIT license
</div>
</div>
<script type="text/javascript">
var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cspan id='cnzz_stat_icon_1264021086'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s22.cnzz.com/z_stat.php%3Fid%3D1264021086%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
</script>
<script src="plugins/layui/layui.js"></script>
<script>
var message;
layui.config({
base: 'build/js/',
version: '1.0.1'
}).use(['app', 'message'], function() {
var app = layui.app,
$ = layui.jquery,
layer = layui.layer;
//将message设置为全局以便子页面调用
message = layui.message;
//主入口
app.set({
type: 'iframe'
}).init();
$('#pay').on('click', function() {
layer.open({
title: false,
type: 1,
content: '<img src="/src/images/pay.png" />',
area: ['500px', '250px'],
shadeClose: true
});
});
$('dl.skin > dd').on('click', function() {
var $that = $(this);
var skin = $that.children('a').data('skin');
switchSkin(skin);
});
var setSkin = function(value) {
layui.data('kit_skin', {
key: 'skin',
value: value
});
},
getSkinName = function() {
return layui.data('kit_skin').skin;
},
switchSkin = function(value) {
var _target = $('link[kit-skin]')[0];
_target.href = _target.href.substring(0, _target.href.lastIndexOf('/') + 1) + value + _target.href.substring(_target.href.lastIndexOf('.'));
setSkin(value);
},
initSkin = function() {
var skin = getSkinName();
switchSkin(skin === undefined ? 'default' : skin);
}();
});
</script>
</body>
<body>
<script>
layui.use(['table','layer'],function(){
var table=layui.table;
var layer=layui.layer;
var $=layui.jquery;
table.on('tool(test)',function(obj){
var value=obj.value;
var data=obj.data;
var field=obj.field;
layEvent=obj.event;
if(layEvent=="detal"){
//弹出层
layer.open({
type:2,
title:"宿舍长信息",
content:"detais?id="+data.teacher_ID,
area:['450px','500px'],
shade:0.5,
maxmin:true
});
}else if(layEvent=="deleted"){
$.ajax({
type:"get",
url:"delete?id="+data.teacher_ID,
dataType:"text",
success:function(data1){//成功回调函数
obj.del();
layer.msg("删除成功");
}
});
}else if(layEvent=="edit"){
$.ajax({
type:"post",
url:"update?str="+JSON.stringify(data),
dataType:"text",
success:function(data1){//成功回调函数
// obj.del();
layer.msg("更新成功");
}
});
}else if(layEvent=="add"){
layer.open({
type:2,
title:"添加用户",
content:"add.jsp",
area:['450px','500px'],
shade:0.5,
maxmin:true,
end:function(){
location.reload();
}
});
}else if(layEvent=="start"){
$.ajax({
type:"get",
url:"add?id="+data.id+"&&state=1",
dataType:"text",
success:function(data1){//成功回调函数
//obj.del();
location.reload();
}
});
}else if(layEvent=="disable"){
$.ajax({
type:"get",
url:"add?id="+data.id+"&&state=0",
dataType:"text",
success:function(data1){//成功回调函数
//obj.del();
location.reload();
}
});
}
});
var active={
reload:function(){
var sers=$("#search").val();//获得文本框的值
if(sers===""){
layer.msg("你要查找的用户搜索的时候不能为空");
}else{
table.reload("test",{
where:{
sers:sers//把获得的文本框的值传入给sers的参数(赋值)
},
page:{
curr:1
}
});
}
}
}
$("#btnSearch").click(function(){//layui表格要重新加载,所以说我们要监听按钮的事件
var type= $(this).data("type");
active[type]?active[type].call(this):"";
});
});
</script>
<div class="layui-form-item">
<label class="layui-form-label">查找宿管</label>
<div class="layui-input-inline">
<input type="text" id="search" class="layui-input" width="100px" />
<a class="layui-btn" data-type="reload" id="btnSearch" >搜索</a>
</div>
</div>
<table class="layui-table" lay-data="{height:500,url:'findall',page:true,id:'test'}" lay-filter="test" >
<thead>
<th lay-data="{field:'teacher_ID',sort:true,width:100}">宿管编号</th>
<th lay-data="{field:'teacher_Username',sort:true,width:100,edit:true}">用户姓名</th>
<th lay-data="{field:'teacher_Password',sort:true,width:100,edit:true}">用户密码</th>
<th lay-data="{field:'teacher_Name',sort:true,width:100,edit:true}">宿管姓名</th>
<th lay-data="{field:'teacher_Sex',sort:true,width:70,edit:true}">性别</th>
<th lay-data="{field:'teacher_Tel',sort:true,width:70,edit:true}">电话</th>
<th lay-data="{title:'操作',align:'center',width:300,toolbar:'#barDemo'}">操作</th>
</thead>
</table>
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="detal">查看</a>
<a class="layui-btn layui-btn-normal layui-btn-xs " lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="deleted">删除</a>
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="add">添加</a>
</script>
</body>
宿管功能块接口:
public TeacherInfo teacher(String name,String pwd);
public int getCount();
public List<TeacherInfo> findall(int pageSize,int pageCode);
public List<TeacherInfo> findall();
public TeacherInfo findTeacherById(int id);
public int update(TeacherInfo t);
public int delete(int id);
public int add(TeacherInfo t);
实现接口:
public TeacherInfo teacher(String name, String pwd) {
TeacherInfo aa = null;
Connection conn = DButil.getConn();
String sql = "select * from teacher where teacher_Username=? and teacher_Password=? ";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2,pwd);
ResultSet rs =ps.executeQuery();
if (rs.next()){
aa = new TeacherInfo(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6),rs.getString(7));
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
DButil.getConn();
}
return aa;
}
public int getCount() {
Connection conn=DButil.getConn();
int result=0;
String sql="select count(*) from teacher";
try {
PreparedStatement ps=conn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
if(rs.next()){
result= rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DButil.closeConn(conn,null,null);
}
return result;
}
public List<TeacherInfo> findall(int pageSize, int pageCode) {
Connection conn=DButil.getConn();
List<TeacherInfo> lists=new ArrayList<TeacherInfo>();
String sql="select * from teacher limit ?,?";
try {
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1, (pageSize-1)*pageCode);
ps.setInt(2, pageCode);
ResultSet rs=ps.executeQuery();
while(rs.next()){
TeacherInfo t=new TeacherInfo(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7));
lists.add(t);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DButil.closeConn(conn, null, null);
}
return lists;
}
public TeacherInfo findTeacherById(int id) {
// TODO Auto-generated method stub
Connection conn=DButil.getConn();
String sql="select * from teacher where teacher_ID=?";
TeacherInfo t=null;
try {
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1, id);
ResultSet rs=ps.executeQuery();
while(rs.next()){
t=new TeacherInfo(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6),rs.getString(7));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DButil.closeConn(conn, null, null);
}
return t;
}
public int update(TeacherInfo t) {
// TODO Auto-generated method stub
int a=0;
Connection conn=DButil.getConn();
String sql="update teacher set teacher_Username=?,teacher_Password=?,teacher_Name=?,teacher_Sex=?,teacher_Tel=? where teacher_ID=?";
try {
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, t.getTeacher_Username());
ps.setString(2, t.getTeacher_Password());
ps.setString(3, t.getTeacher_Name());
ps.setString(4, t.getTeacher_Sex());
ps.setString(5, t.getTeacher_Tel());
ps.setInt(6, t.getTeacher_ID());
System.out.println(ps.toString());
a=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
public int delete(int id) {
int a=0;
Connection conn=DButil.getConn();
String sql="delete from teacher where teacher_ID=? ";
try {
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1, id);
a=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return a;
}
public int add(TeacherInfo t) {
// TODO Auto-generated method stub
int a=0;
Connection conn=DButil.getConn();
String sql="insert into teacher values(null,?,?,?,?,?)";
try {
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, t.getTeacher_Username());
ps.setString(2, t.getTeacher_Password());
ps.setString(3, t.getTeacher_Name());
ps.setString(4, t.getTeacher_Sex());
ps.setString(5, t.getTeacher_Tel());
a=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
servlet部分过于琐碎,如有需帮助联系我
系统管理员与学生管理员操作同理,此代码仅为部分,如有不对的地方还请一起讨论,共同进步,联系扣扣:2455441814
上一篇: 用java制作一个具有增删改查的简单的学生管理系统
下一篇: C语言——单链表的增删改查