学生页面
studentList.html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>学生列表</title>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/p_StudentManagerSystem/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://localhost:8080/p_StudentManagerSystem/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="http://localhost:8080/p_StudentManagerSystem/easyui/css/demo.css">
<script type="text/javascript" src="http://localhost:8080/p_StudentManagerSystem/easyui/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost:8080/p_StudentManagerSystem/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="http://localhost:8080/p_StudentManagerSystem/easyui/js/validateExtends.js"></script>
<script type="text/javascript">
$(function() {
//详情页面
$("#detail").window({
minimizable:false,
width:600,
height:400,
modal:true,//模态化
iconCls:'icon-large-clipart',
closed:true
});
//datagrid初始化
$('#dataList').datagrid({
title:'学生列表',
iconCls:'icon-more',//图标
border: true,
collapsible:false,//是否可折叠的
fit: true,//自动大小
method: "post",
url:"StuServlet?method=StudentList",
idField:'sno',
singleSelect:false,//是否单选
pagination:true,//分页控件
rownumbers:true,//行号
sortName:'sno',
sortOrder:'DESC',
remoteSort: false,
columns: [[
{field:'chk',checkbox: true,width:50},
{field:'sno',title:'学生编号',width:50, sortable: true},
{field:'sid',title:'用户名',width:200, sortable: true},
{field:'spwd',title:'密码',width:200, sortable: true},
{field:'sname',title:'学生姓名',width:200},
{field:'sgender',title:'性别',width:100},
{field:'sage',title:'学生年龄',width:50},
{field:'stel',title:'电话',width:150},
{field:'saddress',title:'地址',width:150},
{field:'sclass',title:'班级',width:150,
formatter: function(value,row,index){
if (row.sclass){
var ccList = $("#search_sclass").combobox("getData");
for(var i=0;i<ccList.length;i++ ){
//console.log(clazzList[i]);
if(row.sclass == ccList[i].cno)
return ccList[i].cname;
}
return row.sclass;
} else {
return 'not found';
}
}
},
{field:'senterprise',title:'所属公司',width:150,
formatter: function(value,row,index){
if (row.senterprise){
var eeList = $("#search_senterprise").combobox("getData");
for(var i=0;i<eeList.length;i++ ){
//console.log(clazzList[i]);
if(row.senterprise == eeList[i].eno)return eeList[i].ename;
}
return row.senterprise;
} else {
return 'not found';
}
}
},
{field:'smtime',title:'入学时间',width:150},
{field:'sstatus',title:'状态',width:50,
formatter: function(value,row,index){
if(row.sstatus==0){
return "已毕业";
}else if(row.sstatus==1){
return "学习中";
}
}
},
]],
//鼠标双击事件
onDblClickRow:function(index,student){
var status="";
if(student.sstatus==0){
status="已毕业";
}
if(student.sstatus==1){
status="学习中";
}
var sclassList = $("#search_sclass").combobox("getData");
var senterpriseList = $("#search_senterprise").combobox("getData");
//alert(sclassList[index].cname);
$("#detail").window('open'); // open a window
$("#desc_sno").html(student.sno);
$("#desc_sid").html(student.sid);
$("#desc_spwd").html(student.spwd);
$("#desc_sname").html(student.sname);
$("#desc_sgender").html(student.sgender);
$("#desc_sage").html(student.sage);
$("#desc_stel").html(student.stel);
$("#desc_saddress").html(student.saddress);
$("#desc_sclass").html(sclassList[index].cname);
$("#desc_senterprise").html(senterpriseList[index].ename);
$("#desc_smtime").html(student.smtime);
$("#desc_sstatus").html(status);
} ,
toolbar: "#toolbar",
onBeforeLoad : function(){
try{
$("#search_sclass").combobox("getData");
$("#search_senterprise").combobox("getData");
}catch(err){
preLoadClass();
preLoadEnt();
}
}
});
//设置分页控件
var p = $('#dataList').datagrid('getPager');
$(p).pagination({
pageSize: 10,//每页显示的记录条数,默认为10
pageList: [10,20,30,50,100],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
});
//设置工具类按钮
$("#add").click(function(){
$("#addDialog").dialog("open");
});
//修改
$("#edit").click(function(){
var selectRows = $("#dataList").datagrid("getSelections");
if(selectRows.length != 1){
$.messager.alert("消息提醒", "请选择一条数据进行操作!", "warning");
} else{
$("#editDialog").dialog("open");
}
});
//删除
$("#delete").click(function(){
var selectRows = $("#dataList").datagrid("getSelections");
var selectLength = selectRows.length;
if(selectLength == 0){
$.messager.alert("消息提醒", "请选择数据进行删除!", "warning");
} else{
var snos='';
$(selectRows).each(function(i, row){
snos=snos+ row.sno+",";
});
snos= snos.substring(0,snos.lastIndexOf(','));
alert("确定要删除?" + snos);
$.messager.confirm("消息提醒", "将删除与学生相关的所有数据,确认继续?", function(r){
if(r){
$.ajax({
type: "post",
url: "StuServlet?method=DeleteStudent",
data: {snos:snos},
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","删除成功!","info");
//刷新表格
$("#dataList").datagrid("reload");
$("#dataList").datagrid("uncheckAll");
} else{
$.messager.alert("消息提醒","删除失败!","warning");
return;
}
}
});
}
});
}
});
//班级下拉框-- 在加载页面时, 同时,页面上方搜索栏里的班级列表也加载!
//在claServlet 和dao方法中有需要更改的东西, 继续放下看。
function preLoadClass(){
$("#search_sclass").combobox({
width: "150",
height: "25",
valueField: "cno",
textField: "cname",
multiple: false, //可多选
editable: true, //不可编辑
method: "post",
url: "ClaServlet?method=getClassList&from=combox",
onChange: function(newValue, oldValue){
}
});
}
//所属公司下拉框 (同上)
function preLoadEnt(){
$("#search_senterprise").combobox({
width: "150",
height: "25",
valueField: "eno",
textField: "ename",
multiple: false, //可多选
editable: false, //不可编辑
method: "post",
url: "EntServlet?method=entList&from=combox",
onChange: function(newValue, oldValue){
//加载班级下的学生
//$('#dataList').datagrid("options").queryParams = {clazzid: newValue};
//$('#dataList').datagrid("reload");
}
});
}
//下拉框通用属性--班级 (在设置增加窗口,和更新窗口 中班级的下拉列表问题)
$("#add_sclass, #edit_sclass").combobox({
width: "200",
height: "30",
valueField: "cno",
textField: "cname",
multiple: false, //可多选
editable: false, //不可编辑
method: "post",
});
$("#add_sclass").combobox({
url: "ClaServlet?method=getClassList&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");;
$(this).combobox("setValue", data[0].cno);
}
});
$("#edit_sclass").combobox({
url: "ClaServlet?method=getClassList&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");
$(this).combobox("setValue", data[0].cno);
}
});
//下拉框通用属性--企业
$("#add_senterprise, #edit_senterprise").combobox({
width: "200",
height: "30",
valueField: "eno",
textField: "ename",
multiple: false, //可多选
editable: false, //不可编辑
method: "post",
});
$("#add_senterprise").combobox({
url: "EntServlet?method=entList&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");;
$(this).combobox("setValue", data[0].eno);
}
});
$("#edit_senterprise").combobox({
url: "EntServlet?method=entList&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");
$(this).combobox("setValue", data[0].eno);
}
});
//设置添加学生窗口
$("#addDialog").dialog({
title: "添加学生",
width: 650,
height: 420,
iconCls: "icon-add",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'添加',
plain: true,
iconCls:'icon-user_add',
handler:function(){
var validate = $("#addForm").form("validate");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
$.ajax({
type: "post",
url: "StuServlet?method=AddStudent",
data: $("#addForm").serialize(),
success: function(msg){
if(msg.trim() == "success"){
$.messager.alert("消息提醒","添加成功!","info");
//关闭窗口
$("#addDialog").dialog("close");
//清空原表格数据
$("#add_sid").textbox('setValue', "");
$("#add_spwd").textbox('setValue', "");
$("#add_sname").textbox('setValue', "");
$("#add_sgender").textbox('setValue', "男");
$("#add_sage").textbox('setValue', "");
$("#add_stel").textbox('setValue', "");
$("#add_saddress").textbox('setValue', "");
/* $("#add_sclass").textbox('setValue', "");
$("#add_senterprise").textbox('setValue', ""); */
$("#add_smtime").textbox('setValue', "");
$("#add_sstatus").combobox('setValue', "");
//重新刷新页面数据
//$('#dataList').datagrid("options").queryParams = {add_sclass: add_sclass,add_senterprise:add_senterprise};
$('#dataList').datagrid("reload");
$('#dataList').datagrid("uncheckAll");
/* setTimeout(function(){
$("#search_sclass").combobox('setValue', add_sclass);
//$("#search_senterprise").combobox('setValue', add_senterprise);
}, 100); */
} else{
$.messager.alert("消息提醒","添加失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
$("#add_sid").textbox('setValue', "");
$("#add_spwd").textbox('setValue', "");
$("#add_sname").textbox('setValue', "");
$("#add_sgender").textbox('setValue', "男");
$("#add_sage").textbox('setValue', "");
$("#add_stel").textbox('setValue', "");
$("#add_saddress").textbox('setValue', "");
$("#add_sclass").textbox('setValue', "");
$("#add_senterprise").textbox('setValue', "");
$("#add_smtime").textbox('setValue', "");
$("#add_sstatus").textbox('setValue', "");
//重新加载班级
$("#add_sclass").combobox("clear");
$("#add_sclass").combobox("reload");
//重新加载公司
$("#add_senterprise").combobox("clear");
$("#add_senterprise").combobox("reload");
}
},
]
});
//设置编辑学生窗口
$("#editDialog").dialog({
title: "修改学生信息",
width: 650,
height: 460,
iconCls: "icon-edit",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'提交',
plain: true,
iconCls:'icon-user_add',
handler:function(){
var validate = $("#editForm").form("validate");
var edit_sclass = $("#edit_sclass").combobox("getValue");
var edit_senterprise = $("#edit_senterprise").combobox("getValue");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
$.ajax({
type: "post",
url: "StuServlet?method=EditStudent&edit_sno="+$("#dataList").datagrid("getSelected").sno,
data: $("#editForm").serialize(),
success: function(msg){
if(msg.trim() == "success"){
$.messager.alert("消息提醒","更新成功!","info");
//关闭窗口
$("#editDialog").dialog("close");
//刷新表格
$('#dataList').datagrid("options").queryParams = {edit_sclass: edit_sclass};
$('#dataList').datagrid("options").queryParams = {edit_senterprise: edit_senterprise};
$("#dataList").datagrid("reload");
$("#dataList").datagrid("uncheckAll");
/* setTimeout(function(){
$("#search_sclass").combobox('setValue', edit_sclass);
$("#search_senterprise").combobox('setValue', edit_senterprise);
}, 100); */
} else{
$.messager.alert("消息提醒","更新失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
$("#edit_sname").textbox('setValue', "");
$("#edit_sgender").textbox('setValue', "男");
$("#edit_sage").textbox('setValue', "");
$("#edit_stel").textbox('setValue', "");
$("#edit_saddress").textbox('setValue', "");
$("#edit_smtime").textbox('setValue', "");
$("#edit_sstatus").textbox('setValue', "");
$("#edit_sclass").combobox("clear");
$("#edit_senterprise").combobox("clear");
$("#edit_sclass").combobox("reload");
$("#edit_senterprise").combobox("reload");
}
}
],
onBeforeOpen: function(){
var selectRow = $("#dataList").datagrid("getSelected");
//设置值
$("#edit_sname").textbox('setValue', selectRow.sname);
$("#edit_sgender").textbox('setValue', selectRow.sgender);
$("#edit_sage").textbox('setValue', selectRow.sage);
$("#edit_stel").textbox('setValue',selectRow.stel);
$("#edit_saddress").textbox('setValue', selectRow.saddress);
$("#edit_smtime").textbox('setValue', selectRow.smtime);
//$("#edit_sstatus").textbox('setValue', selectRow.sstatus);
$("#edit_sstatus").combobox('setValue', selectRow.sstatus);
//$("#edit_sstatus").val(selectRow.sstatus);
$("#edit_sclass").textbox('setValue', selectRow.sclass);
$("#edit_senterprise").textbox('setValue', selectRow.senterprise);
//$("#edit_photo").attr("src", "PhotoServlet?method=getPhoto&type=2&sid="+selectRow.id);
//$("#edit-id").val(selectRow.id);
//$("#set-photo-id").val(selectRow.id);
var edit_sclass = selectRow.sclass;
var edit_senterprise = selectRow.senterprise;
setTimeout(function(){
$("#edit_sclass").combobox('setValue', edit_sclass);
$("#edit_senterprise").combobox('setValue', edit_senterprise);
}, 100);
}
});
//搜索按钮监听事件
$("#search-btn").click(function(){
$('#dataList').datagrid('load',{
//拿到给定ID的的值!
sname: $("#search_sname").val(),
//拿到combobox里显示的值!
sclass: $("#search_sclass").combobox('getValue') ,
senterprise: $("#search_senterprise").combobox('getValue'),
});
});
});
//上传图片按钮事件
$("#upload-photo-btn").click(function(){
});
function uploadPhoto(){
var action = $("#uploadForm").attr('action');
var pos = action.indexOf('sid');
if(pos != -1){
action = action.substring(0,pos-1);
}
$("#uploadForm").attr('action',action+'&sid='+$("#set-photo-id").val());
$("#uploadForm").submit();
setTimeout(function(){
var message = $(window.frames["photo_target"].document).find("#message").text();
$.messager.alert("消息提醒",message,"info");
$("#edit_photo").attr("src", "PhotoServlet?method=getPhoto&sid="+$("#set-photo-id").val());
}, 1500)
}
</script>
</head>
<body>
<!-- 学生列表 -->
<table id="dataList" cellspacing="0" cellpadding="0" >
</table>
<!-- 工具栏 -->
<div id="toolbar" style="padding-bottom:30px;background:#F4F4F4;">
<!-- <c:if test="${userType == 1 || userType == 3}"> -->
<div style="float: left;"><a id="add" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a></div>
<div style="float: left;" class="datagrid-btn-separator"></div>
<!-- </c:if> -->
<div style="float: left;"><a id="edit" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a></div>
<div style="float: left;" class="datagrid-btn-separator"></div>
<!-- <c:if test="${userType == 1 || userType == 3}"> -->
<div style="float: left;"><a id="delete" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-some-delete',plain:true">删除</a></div>
<!-- </c:if> -->
<div style="float: left;margin-top:4px;" class="datagrid-btn-separator" > 姓名:<input id="search_sname" class="easyui-textbox" name="search_sname" /></div>
<div style="margin-left: 10px;margin-top:4px; float: left;" >
班级:<input id="search_sclass" class="easyui-textbox" name="search_sclass" />
</div>
<div style="margin-left: 10px;margin-top:4px; float: left;" >
所属公司:<input id="search_senterprise" class="easyui-textbox" name="search_senterprise" />
<a id="search-btn" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">搜索</a>
</div>
</div>
<!-- 添加学生窗口 -->
<div id="addDialog" style="padding: 10px">
<!-- <div style="float: right; margin: 20px 20px 0 0; width: 200px; border: 1px solid #EBF3FF" id="photo">
<img alt="照片" style="max-width: 200px; max-height: 400px;" title="照片" src="PhotoServlet?method=getPhoto" />
</div> -->
<form id="addForm" method="post">
<table cellpadding="8" >
<tr>
<td>用户名:</td>
<td><input id="add_sid" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="add_sid" data-options="required:true, missingMessage:'请填写用户名'" /></td>
</tr>
<tr>
<td>密码:</td>
<td>
<input id="add_spwd" class="easyui-textbox" style="width: 200px; height: 30px;" type="password" name="add_spwd" data-options="required:true, missingMessage:'请输入登录密码'" />
</td>
</tr>
<tr>
<td>学生名字:</td>
<td><input id="add_sname" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="add_sname" data-options="required:true, missingMessage:'请填写学生姓名'" /></td>
</tr>
<tr>
<td>性别:</td>
<td><select id="add_sgender" class="easyui-combobox" data-options="editable: false, panelHeight: 50, width: 60, height: 30" name="add_sgender"><option value="男">男</option><option value="女">女</option></select></td>
</tr>
<tr>
<td>年龄:</td>
<td><input id="add_sage" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="add_sage" /></td>
</tr>
<tr>
<td>电话:</td>
<td><input id="add_stel" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="add_stel" /></td>
</tr>
<tr>
<td>地址:</td>
<td><input id="add_saddress" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="add_saddress" /></td>
</tr>
<tr>
<td>班级:</td>
<td><input id="add_sclass" style="width: 200px; height: 30px;" class="easyui-textbox" name="add_sclass" /></td>
</tr>
<tr>
<td>所属公司:</td>
<td><input id="add_senterprise" style="width: 200px; height: 30px;" class="easyui-textbox" name="add_senterprise" /></td>
</tr>
<tr>
<td>入学时间:</td>
<td><input id="add_smtime" type= "date" style="width: 200px; height: 30px;" class="easyui-textbox" name="add_smtime" /></td>
</tr>
<tr>
<td>状态:</td>
<td>
<select id="add_sstatus" class="easyui-combobox" style="width: 200px; height: 30px;" name="add_sstatus">
<option value="0">已毕业</option>
<option value="1">学习中</option>
</select>
<!-- <input id="add_sstatus" type= "text" style="width: 200px; height: 30px;" class="easyui-textbox" name="add_sstatus" /> -->
</td>
</tr>
</table>
</form>
</div>
<!-- 修改学生窗口 -->
<div id="editDialog" style="padding: 10px">
<!-- <div style="float: right; margin: 20px 20px 0 0; width: 200px; border: 1px solid #EBF3FF">
<img id="edit_photo" alt="照片" style="max-width: 200px; max-height: 400px;" title="照片" src="" />
<form id="uploadForm" method="post" enctype="multipart/form-data" action="PhotoServlet?method=SetPhoto" target="photo_target">
StuServlet?method=SetPhoto
<input type="hidden" name="sid" id="set-photo-id">
<input class="easyui-filebox" name="photo" data-options="prompt:'选择照片'" style="width:200px;">
<input id="upload-photo-btn" onClick="uploadPhoto()" class="easyui-linkbutton" style="width: 50px; height: 24px;" type="button" value="上传"/>
</form>
</div> -->
<form id="editForm" method="post">
<input type="hidden" name="edit-sno" id="edit-sno">
<table cellpadding="8" >
<tr>
<td>学生名字:</td>
<td><input id="edit_sname" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="edit_sname" data-options="required:true, missingMessage:'请填写姓名'" /></td>
</tr>
<tr>
<td>性别:</td>
<td><select id="edit_sgender" class="easyui-combobox" data-options="editable: false, panelHeight: 50, width: 60, height: 30" name="edit_sgender"><option value="男">男</option><option value="女">女</option></select></td>
</tr>
<tr>
<td>年龄:</td>
<td><input id="edit_sage" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="edit_sage" /></td>
</tr>
<tr>
<td>电话:</td>
<td><input id="edit_stel" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="edit_stel" validType="mobile" /></td>
</tr>
<tr>
<td>地址:</td>
<td><input id="edit_saddress" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="edit_saddress" /></td>
</tr>
<tr>
<td>班级:</td>
<td><input id="edit_sclass" style="width: 200px; height: 30px;" class="easyui-textbox" name="edit_sclass" /></td>
</tr>
<tr>
<td>所属公司:</td>
<td><input id="edit_senterprise" style="width: 200px; height: 30px;" class="easyui-textbox" name="edit_senterprise" /></td>
</tr>
<tr>
<td>入学时间:</td>
<td><input id="edit_smtime" type= "date" style="width: 200px; height: 30px;" class="easyui-textbox" name="edit_smtime" /></td>
</tr>
<tr>
<td>状态:</td>
<td>
<select id="edit_sstatus" class="easyui-combobox" style="width: 200px; height: 30px;" name="edit_sstatus">
<option value="0">已毕业 </option>
<option value="1">学习中</option>
</select>
</td>
<!-- <td><input id="edit_sstatus" type= "text" style="width: 200px; height: 30px;" class="easyui-textbox" name="edit_sstatus" /></td> -->
</tr>
</table>
</form>
</div>
<!-- 详情页面窗口 -->
<div id="detail" class="easyui-window" title="企业详情" >
<table border="1px" bordercolor="#000000" width="100%" hight="100%"
cellspacing="0px" style="border-collapse:collapse">
<tr>
<td>编号:</td>
<td id="desc_sno"></td>
</tr>
<tr>
<td>用户名:</td>
<td id="desc_sid"></td>
</tr>
<tr>
<td>密码:</td>
<td id="desc_spwd"></td>
</tr>
<tr>
<td>学生名字:</td>
<td id="desc_sname"></td>
</tr>
<tr>
<td>性别:</td>
<td id="desc_sgender"></td>
</tr>
<tr>
<td>年龄:</td>
<td id="desc_sage"></td>
</tr>
<tr>
<td>电话:</td>
<td id="desc_stel"></td>
</tr>
<tr>
<td>地址:</td>
<td id="desc_saddress"></td>
</tr>
<tr>
<td>班级:</td>
<td id="desc_sclass"></td>
</tr>
<tr>
<td>所属公司:</td>
<td id="desc_senterprise"></td>
</tr>
<tr>
<td>入学时间:</td>
<td id="desc_smtime"></td>
</tr>
<tr>
<td>状态:</td>
<td id="desc_sstatus"></td>
</tr>
</table>
</div>
<!-- 提交表单处理iframe框架 -->
<iframe id="photo_target" name="photo_target"></iframe>
</body>
</html>
ClassServlet中
ClaServlet.java
//要做一种情况 为combobox加载
if(method.equals("getClassList")&&from.equals("combox")) {
//做一个集合装班级
ArrayList<ClassTab> al=new ArrayList<>();
//做一个集合装map (就要求 传这格式。)
ArrayList<Map <String, Object>> ccll=new ArrayList<Map <String, Object>> ();
//调用方法来获取全部班级 ,这个方法在下面。
al= cd.loadClassList();
for(ClassTab c:al) {
Map<String, Object> map =new HashMap<String, Object>();
map.put("cno", c.getCno());
map.put("cname",c.getCname());
ccll.add(map);
}
response.getWriter().println(JSONArray.fromObject(ccll));
}
dao方法中
daoImpl.java
//获取全部班级的方法
public ArrayList<ClassTab> loadClassList() {
String sql="select * from ClassTab " ;
Object [] obj= {};
ResultSet rs= DBUtils.query(sql, obj);
//create a list for ClassTab
ArrayList<ClassTab> al=new ArrayList<ClassTab>();
try {
while (rs.next()){
//new新对象
ClassTab ct=new ClassTab(rs.getInt("cno"),
rs.getString("cname"),rs.getString("caddress"),
rs.getInt("cstatus"));
//放进集合
al.add(ct);
}
return al;
}catch (SQLException e) {
e.printStackTrace();
}
return null;
}