jsp页面代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>项目管理</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css"
href="js/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="js/themes/icon.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src='js/outlook2.js'>
</script>
<script type="text/javascript">
var url;
var type;
function newpm() {
$("#dlg").dialog("open").dialog('setTitle', '新建项目');
$("#fm").form("clear");
url = "addItem.action";
document.getElementById("hidtype").value = "submit";
}
function editpm() {
var row = $("#dg").datagrid("getSelected");
if (row) {
$("#dlg").dialog("open").dialog('setTitle', '修改项目');
$("#fm").form("load", row);
url = "updateItem.action?PMID=" + row.PMID;
}
}
function savepm() {
$("#fm").form("submit", {
url : url,
onsubmit : function() {
return $(this).form("validate");
},
success : function(result) {
if (result == "1") {
$.messager.alert("提示信息", "操作成功");
$("#dlg").dialog("close");
$("#dg").datagrid("load");
} else {
$.messager.alert("提示信息", "操作失败");
}
}
});
}
function destroypm() {
var row = $("#dg").datagrid("getSelected");
var url = "removeItem.action?PMID=" + row.PMID;
if (row) {
$.messager.confirm('Confirm', '确定删除?', function(r) {
if (r) {
$.ajax({
url : url,
type : "POST",
success : function(result) {
if (result == "1") {
$('#dg').datagrid('reload');
$.messager.show({
title : 'success',
msg : '删除成功!'
});
} else {
$.messager.show({ // show error message
title : 'Error',
msg : '删除失败!'
});
}
}
});
}
});
}
}
</script>
<style type="text/css">
#fm {
margin: 0;
padding: 10px 30px;
}
.ftitle {
font-size: 14px;
font-weight: bold;
padding: 5px 0;
margin-bottom: 10px;
border-bottom: 1px solid #ccc;
}
.fitem {
margin-bottom: 5px;
}
.fitem label {
display: inline-block;
width: 80px;
}
</style>
</head>
<body>
<div id="toolbar">
<a href="javascript:void(0)" class="easyui-linkbutton"
iconcls="icon-add" οnclick="newpm()" plain="true">添加</a> <a
href="javascript:void(0)" class="easyui-linkbutton"
iconcls="icon-edit" οnclick="editpm()" plain="true">修改</a> <a
href="javascript:void(0)" class="easyui-linkbutton"
iconcls="icon-remove" οnclick="destroypm()" plain="true">删除</a>
</div>
<table id="dg" title="项目管理" class="easyui-datagrid"
style="width: 100%; height: 500px" url="getall.action"
toolbar="#toolbar" pagination="true" rownumbers="true"
fitcolumns="true" singleselect="true">
<thead>
<tr>
<th field="PMID" width="50">项目编号</th>
<th field="PMName" width="50">项目名称</th>
<th field="pman" width="50">项目经理</th>
<th field="PIntroduction" width="50">项目介绍</th>
<th field="PTenders" width="50">项目标段</th>
<th field="budget" width="50">项目预算</th>
<th field="delaycost" width="50">延期成本</th>
<th field="ptime" width="50">项目预期</th>
</tr>
</thead>
</table>
<div id="dlg" class="easyui-dialog"
style="width: 80%; height: 100%; padding: 20px 40px;" closed="true"
buttons="#dlg-buttons">
<div class="ftitle">信息编辑</div>
<form id="fm" method="post">
<div class="fitem">
<label> 项目名称</label> <input name="PMName" class="easyui-validatebox"
required="true" />
</div>
<div class="fitem">
<label> 项目经理</label> <input name="pman" class="easyui-validatebox" />
</div>
<div class="fitem">
<label> 项目介绍</label> <input name="PIntroduction"
class="easyui-validatebox" />
</div>
<div class="fitem">
<label> 项目标段</label> <input name="PTenders"
class="easyui-vlidatebox" />
</div>
<div class="fitem">
<label> 项目预算</label> <input name="budget" class="easyui-vlidatebox" />
</div>
<div class="fitem">
<label> 延期成本</label> <input name="delaycost"
class="easyui-vlidatebox" />
</div>
<div class="fitem">
<label> 项目预期</label> <input name="ptime" class="easyui-vlidatebox" />
</div>
<input type="hidden" name="action" id="hidtype" /> <input
type="hidden" name="ID" id="Nameid" />
</form>
</div>
<div id="dlg-buttons">
<a href="javascript:void(0)" class="easyui-linkbutton"
οnclick="savepm()" iconcls="icon-save">保存</a> <a
href="javascript:void(0)" class="easyui-linkbutton"
οnclick="javascript:$('#dlg').dialog('close')" iconcls="icon-cancel">取消</a>
</div>
</body>
</html>
action代码:
package com.rt.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rt.model.PmInfo;
import com.rt.service.PmInfoService;
@Controller
public class PmInfoAction {
private PmInfoService pmInfoService;
public PmInfoService getPmInfoService() {
return pmInfoService;
}
public void setPmInfoService(PmInfoService pmInfoService) {
this.pmInfoService = pmInfoService;
}
@RequestMapping(value = "/getall.action")
public void getalls(HttpServletRequest req, HttpServletResponse resp) {//显示全部
resp.setCharacterEncoding("utf-8");//转为UTF-8输出
List<PmInfo> list = pmInfoService.getList(null);
JSONArray json = JSONArray.fromObject(list);
String jsonn = json.toString();
PrintWriter pw;
try {
pw = resp.getWriter();
pw.print(jsonn);
pw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@RequestMapping(value = "/addItem.action", method = RequestMethod.POST)
@ResponseBody
public String addItem(PmInfo p) {//增加
String result = "0";
if (pmInfoService.addItem(p) > 0) {
result = "1";
} else {
result = "0";
}
return result;
}
@RequestMapping(value = "/updateItem.action", method = RequestMethod.POST)
@ResponseBody
public String updateItem(PmInfo p) {//修改
String result = "1";
if (pmInfoService.updateItem(p) > 0) {
result = "1";
} else {
result = "0";
}
return result;
}
@RequestMapping(value = "/removeItem.action", method = RequestMethod.POST)
@ResponseBody
public String removeItem(PmInfo p) {//删除
System.out.println(p.getPMID());
String result = "1";
if (pmInfoService.removeItem(p) > 0) {
result = "1";
} else {
result = "0";
}
return result;
}
}