1、今日完成任务:
(1)完成档案管理-驾驶员信息管理模块的代码书写及测试工作
2、核心源码:
package com.dw.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dw.entity.Driver;
import com.dw.service.DriverService;
@Controller
public class DriverController {
@Autowired
private DriverService ds;
@RequestMapping("/queryAllDriver")
@ResponseBody
public List<Driver> queryAllDriver(){
try {
List<Driver> list = ds.queryAll();
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@RequestMapping("/saveDriver")
@ResponseBody
public void saveDriver(Driver driver){
try {
ds.save(driver);
} catch (Exception e) {
e.printStackTrace();
}
}
@RequestMapping("/deleteDriver/{ids}")
@ResponseBody
public void deleteDriver(@PathVariable("ids")String ids){
String[] strings = ids.split(",");
try {
for (String id : strings) {
ds.delete(Integer.parseInt(id));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>驾驶员信息管理</title>
<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css"/>
<link rel="stylesheet" type="text/css" href="../../js/easyui/ext/portal.css"/>
<link rel="stylesheet" type="text/css" href="../../css/default.css"/>
<script src="../../js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/easyui/ext/jquery.portal.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$('#dg').datagrid({
toolbar: [{
id: 'add',
text:'添加',
iconCls: 'icon-add',
handler: function(){
$("#win").window('open');
$("#ff").form('reset');
}
},'-',{
id: 'edit',
text:'修改',
iconCls: 'icon-edit',
handler: function(){
var rows = $("#dg").datagrid('getSelections');
if(rows.length!=1){
$.messager.alert('提示信息','修改时必须选择一行数据!','warning');
}else{
$("#ff").form('load',rows[0]);
$("#win").window('open');
}
}
},'-',{
id: 'delete',
text:'删除',
iconCls: 'icon-remove',
handler: function(){
var rows = $("#dg").datagrid('getSelections');
if(rows.length==0){
$.messager.alert('提示信息','删除时至少选择一行数据!','warning');
}else{
var ids = new Array();
for (var i = 0; i < rows.length; i++) {
ids.push(rows[i].id);
}
$.messager.confirm('确认对话框', '您确定要删除吗?', function(r){
if (r){
$.post('../../deleteDriver/'+ids.join(","),function(data){
$("#dg").datagrid('reload');
});
}
});
}
}
}]
});
$("#save").click(function(){
if($("#ff").form('validate')){
$("#ff").form('submit',{
success:function(data){
$("#win").window('close');
$("#dg").datagrid('reload');
}
});
}else{
$.messager.alert('警告','表单中包含非法数据!','warning');
}
});
})
</script>
</head>
<body>
<table id="dg" class="easyui-datagrid"
data-options="url:'../../queryAllDriver',fitColumns:true,rownumbers:true">
<thead>
<tr>
<th data-options="field:'id',width:100,align:'center',checkbox:true"></th>
<th data-options="field:'name',width:100,align:'center'">驾驶员姓名</th>
<th data-options="field:'idcard',width:100,align:'center'">身份证号</th>
<th data-options="field:'phone',width:100,align:'center'">联系电话</th>
<th data-options="field:'address',width:100,align:'center'">联系地址</th>
<th data-options="field:'drivervalidity',width:100,align:'center'">驾照有效期</th>
<th data-options="field:'workvalidity',width:100,align:'center'">上岗证有效期</th>
</tr>
</thead>
</table>
<div id="win" class="easyui-window" title="添加修改驾驶员信息" style="width:550px;height:350px;"
data-options="modal:true,minimizable:false,maximizable:false,closed:true">
<div class="datagrid-toolbar">
<a id="save" href="#" class="easyui-linkbutton" icon="icon-save">保存</a>
</div>
<form id="ff" method="post" action="../../saveDriver">
<table class="table-edit" align="center" width="80%">
<tr class="title">
<td colspan="2">驾驶员信息<input type="hidden" name="id"/></td>
</tr>
<tr>
<td>驾驶员姓名:</td>
<td><input class="easyui-validatebox" type="text" name="name" data-options="required:true" /></td>
</tr>
<tr>
<td>身份证号:</td>
<td><input class="easyui-validatebox" type="text" name="idcard" data-options="required:true" /></td>
</tr>
<tr>
<td>联系电话:</td>
<td><input class="easyui-validatebox" type="text" name="phone" data-options="required:true" /></td>
</tr>
<tr>
<td>联系地址:</td>
<td><input class="easyui-validatebox" type="text" name="address" data-options="required:true" /></td>
</tr>
<tr>
<td>驾照有效期:</td>
<td><input class="easyui-validatebox" type="date" name="drivervalidity" data-options="required:true" /></td>
</tr>
<tr>
<td>上岗证有效期:</td>
<td><input class="easyui-validatebox" type="date" name="workvalidity" data-options="required:true" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
3、遇到的问题:
无
4、解决的方法:
无
5、项目燃尽图更新: