1.表单添加保存操作SaveDocument(),方法名与父类一样时,会覆盖父类的方法。此处可换成其他方法名
2.在表单界面ExpenseRequest_Info.jsp实现方法SaveDocument()
//保存功能的实现
function SaveDocument()
{
var formname = document.FormTemplate;
$.ajax({
cache: true,
type: "POST",
dataType:"json",
url:"<%=request.getContextPath()%>/scripts/module/expenserequest/ExpenseRequest_Save.jsp",
data:$(formname).serialize(),//把表单值序列化
async: false,
error: function(request) {
alert("error");
},
success: function(data) {
if(data.code==0)
{
alert(data.msg);
}else
{
//重新加载页面
var url = "<%=request.getContextPath()%>/scripts/common/file/File_Info_Template.jsp?FormID=2c99861257e179a20157e17eb4eb0003&IDField=FileID&FileID=" + data.data;
document.getElementById("reload").href=url;
document.getElementById("reload").click();
}
}
});
}
3.在ExpenseRequest_Save.jsp实现保存数据方法
<%@page import="com.costech.common.util.json.JSONArray"%>
<%@page import="com.costech.common.util.json.JSONObject"%>
<%@page contentType="text/html;charset=UTF-8" %>
<%@page import="com.costech.common.util.StringUtility"%>
<%@page import="com.costech.common.helper.BeanDataHelper"%>
<%@page import="com.costech.common.bean.SystemPath"%>
<%@page import="com.costech.common.helper.ServiceHelper"%>
<%@page import="com.costech.module.expenserequest.helper.ExpenseRequestHelper" %>
<%@page import="com.costech.module.expenserequest.service.IExpenseRequestService" %>
<%@page import="com.costech.module.expenserequest.bean.ExpenseRequest" %>
<%@page import="com.costech.module.expenserequest.bean.ExpenseRequestDetail" %>
<%
request.setCharacterEncoding("UTF-8");
try{
IExpenseRequestService iExpenseRequestService = (IExpenseRequestService)ServiceHelper.getService("expenseRequestService");
//获取界面值
String FileID = request.getParameter("FileID");
String Number = request.getParameter("Number");
String Status = request.getParameter("Status");
String CreateTime = request.getParameter("CreateTime");
String BizDate = request.getParameter("BizDate");
String ApplierID = request.getParameter("ApplierID");
String[] amount = request.getParameterValues("amount");
String[] fileID = request.getParameterValues("fileID");
String[] parentID = request.getParameterValues("parentID");
String[] remark = request.getParameterValues("remark");
String[] expenseType = request.getParameterValues("expenseType");
//封装成JSON格式的参数
JSONObject json = new JSONObject();
json.put("FileID", FileID);
json.put("Number", Number);
json.put("Status", Status);
json.put("CreateTime", CreateTime);
json.put("BizDate", BizDate);
json.put("ApplierID", ApplierID);
JSONArray jsonArray = new JSONArray();
for(int i=0;i<fileID.length;i++)
{
JSONObject json1 = new JSONObject();
json1.put("amount", amount[i]);
json1.put("fileID", fileID[i]);
json1.put("parentID", parentID[i]);
json1.put("remark", remark[i]);
json1.put("expenseType", expenseType[i]);
jsonArray.put(json1);
}
json.put("detailList", jsonArray);
//调用保存方法
String pk = iExpenseRequestService.saveSelf(json.toString());
JSONObject retJson = new JSONObject();
retJson.put("code", "1");
retJson.put("msg", "操作成功");
retJson.put("data", pk);
retJson.put("total", "0");
out.write(retJson.toString());
} catch (Exception e) {
e.printStackTrace();
JSONObject retJson = new JSONObject();
retJson.put("code", "0");
retJson.put("msg", e.getMessage());
retJson.put("data", "");
retJson.put("total", "0");
out.write(retJson.toString());
}
%>
4.方法String pk = iExpenseRequestService.saveSelf(json.toString());在spring中配置接口的事务
<!-- 费用报销实现类 -->
<bean id="expenseRequestServiceTarget"
class="com.costech.module.expenserequest.service.impl.ExpenseRequestServiceImpl">
<property name="jdbcDao" ref="jdbcDao" />
</bean>
<bean id="expenseRequestService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager" />
<property name="target" ref="expenseRequestServiceTarget" />
<property name="transactionAttributes">
<props>
<prop key="exist*">PROPAGATION_NOT_SUPPORTED,readOnly</prop>
<prop key="select*">PROPAGATION_NOT_SUPPORTED,readOnly</prop>
<prop key="get*">PROPAGATION_NOT_SUPPORTED,readOnly</prop>
<prop key="find*">PROPAGATION_NOT_SUPPORTED,readOnly</prop>
<prop key="read*">PROPAGATION_NOT_SUPPORTED,readOnly</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>