本文前端使用JSP,后端Java spring +mybatis,学习笔记
1. 引用jquery.ui.dialog.js,
2.重写open,close函数
/**
* Pa.dialog.js
* depend on jquery.ui.dialog.js
* author:wangtao719
*/
(function(){
/*
* jquery-ui-dialog
* url:
* message:message
* close
* open
*/
var _dialog = {
open : function(opts){
var $dialog;
if(opts.url){
$dialog=$('<div></div>').html('<iframe role="iframe" width="100%" height="100%" src="' + opts.url + '" frameborder="no"></iframe>').appendTo('body');
}
else if(opts.message){
$dialog=$('<div></div>').html(opts.message)
}
else if(opts.element){
$dialog = $('#'+opts.element);
}
else{
return null;
}
return $dialog.dialog(opts);
},
close : function(dialog){
if(dialog){
dialog.dialog('close');
}
}
}
if(typeof window.Pa!="object") window.Pa = {};
window.Pa.dialog = _dialog;
})();
3.jsp页面
<!DOCTYPE html >
<html>
<head>
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<%@ page import="com.pingan.ecpub.dto.PageBean" %>
<%@ page import="com.pingan.ecpub.web.util.Constant,com.pingan.ecpub.util.ContextPropertyUtil" %>
<%
PageBean pager = (PageBean)request.getAttribute("pager");
if(pager==null){
pager = new PageBean();
}
%>
<script type="text/javascript">
_createDialog = null;
$(document).ready(function(){
initLinkRef();
$("#refreshBusinessModelList").on("refreshBusinessModelListEvent",function(){
Pa.dialog.close(_createDialog);
queryBusinessModel();
});
});
function queryBusinessModel(){
Pa.dialog.close(_createDialog);
var accountId = $("#accountId").val();
var url = "bond-businessModel.do?accountId=" + accountId;
openPage(url,null,"accountDetailMid_div");
}
function businessModelCreate(accountId){
_createDialog = Pa.dialog.open({
url : "/bond-businessModel.do?disPath=new&chengFlag=N&accountId="+accountId,
title:"新增商业模式",
width:620,
height:300,
modal:true,
bgiframe:true
});
}
function updateBusinessModel(accntBusIndustryId){
_createDialog = Pa.dialog.open({
url : "/bond-businessModel.do?disPath=update&chengFlag=N&accntBusIndustryId="+accntBusIndustryId,
title:"修改商业模式",
width:620,
height:300,
modal:true,
bgiframe:true
});
}
function deleteBusinessModel(accntBusIndustryId){
if(confirm("确定删除该条记录吗?")){
var params = {};
params.service = "commonServiceEcpub";
params.method = "commonDelete";
params.sqlId = "DELETE_CX_ACCNT_BUS_INDUSTRY";
params.accntBusIndustryId = accntBusIndustryId;
var result = asynRequestFunction(params);
if(result){
alert("删除成功");
queryBusinessModel();
}else{
alert("删除失败");
}
}
}
</script>
</head>
<body >
<div id="ajaxContent">
<form id="bondBusinessModelForm" name="bondBusinessModelForm" action="bond-businessModel.do" method="post">
<input id="refreshBusinessModelList" type="hidden" name="refreshBusinessModelList">
<input type="hidden" name="accountId" id="accountId" value="<c:out value='${accountId}'/>" />
<h4> <a class="i-add fr" id="btn_dialog" οnclick="businessModelCreate('<c:out value='${accountId}'/>')" >新增</a>商业模式</h4>
<c:forEach items="${resultList}" var="resultList" varStatus="status">
<div class="border_box">
<pre><c:out value='${resultList.detailInfo}'/></pre>
<p class="title_tip m_t10">
<c:if test="${resultList.loginId == loginId }">
<a class="i-edit fr" οnclick="updateBusinessModel('<c:out value='${resultList.accntBusIndustryId}'/>');return false;">修改</a>
<a class="i-del2 m_r25 fr" οnclick="deleteBusinessModel('<c:out value='${resultList.accntBusIndustryId}'/>');return false;" >删除</a>
</c:if>
<span class="grayText"><c:out value='${resultList.lastName}'/>(<c:out value='${resultList.buName}'/>) 更新于 <c:out value='${resultList.dateUpdated}'/></span>
</p>
</div>
</c:forEach>
<div class="pagination m_c_t">
<pg:pager items="<%=pager.getTotalRecords() %>" index="center"
export="offset,currentPageNumber=pageNumber"
maxPageItems="<%=pager.getPageSize() %>"
maxIndexPages="<%=pager.getIndexPages() %>"
url="bond-businessModel.do" scope="request">
<pg:param name="accountId" />
<ul>
<pg:index export="totalPages=pages">
<pg:first>
<li class="first"><a href="javascript:void(0);"
οnclick="Pa.common.goToPageAjax('<%=pageUrl%>&pager.currentPage=<%=pageNumber%>','ajaxContent')">首页</a>
</li>
</pg:first>
<pg:prev>
<li class="prev"><a href="javascript:void(0);"
οnclick="Pa.common.goToPageAjax('<%=pageUrl%>&pager.currentPage=<%=pageNumber%>','ajaxContent')">上一页</a>
</li>
</pg:prev>
<pg:pages>
<%
if (currentPageNumber == pageNumber) {
%>
<li class="page"><span><%=pageNumber%></span>
</li>
<%
} else {
%>
<li class="page"><a href="javascript:void(0);"
οnclick="Pa.common.goToPageAjax('<%=pageUrl%>&pager.currentPage=<%=pageNumber%>','ajaxContent')"><%=pageNumber%></a>
</li>
<%
}
%>
</pg:pages>
<pg:next>
<li class="next"><a href="javascript:void(0);"
οnclick="Pa.common.goToPageAjax('<%=pageUrl%>&pager.currentPage=<%=pageNumber%>','ajaxContent')">下一页</a>
</li>
</pg:next>
<pg:last>
<li class="last"><a href="javascript:void(0);"
οnclick="Pa.common.goToPageAjax('<%=pageUrl%>&pager.currentPage=<%=pageNumber%>','ajaxContent')">尾页</a>
</li>
</pg:last>
<li>共<%=totalPages%>页</li>
<li>到第<input type="text" value="" name="pageNo"
id="pageNoInput" class="page" />页</li>
<li><a href="javascript:void(0)" title="跳转"
οnclick="Pa.common.goToPage($('#pageNoInput'),'<pg:page><%=pageUrl%></pg:page>',<%=totalPages%>,<%=pager.getPageSize()%>,true,'ajaxContent');return false;"
class="goto" style="padding-left: 15px; margin-right: 5px;">跳转</a>
</li>
</pg:index>
</ul>
</pg:pager>
</div>
</form>
</div>
</body>
</html>
4.Controller配置
<!-- 客户-商业模式列表 -->
<bean name="/bond-businessModel.do" class="com.pingan.ecpub.web.controller.bond.account.AccountBusindustryController">
<property name="viewName">
<value>businessModelView</value>
</property>
<property name="createBusinessModel">
<value>createBusinessModelView</value>
</property>
</bean>
5.Controller代码
package com.pingan.ecpub.web.controller.bond.account;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import com.paic.pafa.app.dto.ServiceRequest;
import com.paic.pafa.app.dto.ServiceResponse;
import com.paic.pafa.app.web.exception.PafaWebException;
import com.paic.pafa.app.web.servlet.ModelAndView;
import com.paic.pafa.app.web.servlet.mvc.AbstractController;
import com.pingan.ecpub.dto.PageBean;
import com.pingan.ecpub.util.LogUtil;
import com.pingan.ecpub.web.controller.opty.util.OpptyUtils;
import com.pingan.ecpub.web.util.CommonFunction;
import com.pingan.ecpub.web.util.WebContextNames;
public class AccountBusindustryController extends AbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String disPath = request.getParameter("disPath");
if("new".equals(disPath)){
return createBusinessModel(request,response);
}else if("update".equals(disPath)){
return updateBusinessModel(request,response);
}else{
return queryBusinessModel(request,response);
}
}
private ModelAndView createBusinessModel(HttpServletRequest request,
HttpServletResponse response)throws PafaWebException, IOException{
Map params = new HashMap();
Map model = new HashMap();
Map userMap = (Map) request.getSession().getAttribute("userProfile");
String chengFlag = request.getParameter("chengFlag");
if(!"Y".equals(chengFlag)){
model.put("accountId", request.getParameter("accountId"));
return new ModelAndView(createBusinessModel, model);
}else{
params.put("disPath", request.getParameter("disPath"));
params.put("accountId", request.getParameter("accountId"));
params.put("type", "BUSINESS_MODEL");
params.put("detailInfo", request.getParameter("detailInfo"));
params.put("loginId", userMap.get("LoginId"));
ServiceRequest serviceRequest = new ServiceRequest();
serviceRequest.setCurrentRequestObject(params);
serviceRequest.setRequestedServiceID("accountBusIndustryAction");
ServiceResponse serviceResponse = dispatchService(serviceRequest, WebContextNames.PAFA_AC);
Map<Object,Object> retModel = serviceResponse.getModel();
model.putAll(retModel);
OpptyUtils.output(JSONObject.fromMap(model), response);
return null;
}
}
private ModelAndView updateBusinessModel(HttpServletRequest request,
HttpServletResponse response)throws PafaWebException, IOException{
Map params = new HashMap();
Map model = new HashMap();
Map userMap = (Map) request.getSession().getAttribute("userProfile");
String chengFlag = request.getParameter("chengFlag");
String disPath = request.getParameter("disPath");
params.put("chengFlag", chengFlag);
params.put("disPath", disPath);
params.put("accntBusIndustryId", request.getParameter("accntBusIndustryId"));
if(!"Y".equals(chengFlag)){
ServiceRequest serviceRequest = new ServiceRequest();
serviceRequest.setCurrentRequestObject(params);
serviceRequest.setRequestedServiceID("accountBusIndustryAction");
ServiceResponse serviceResponse = dispatchService(serviceRequest, WebContextNames.PAFA_AC);
Map<Object,Object> retModel = serviceResponse.getModel();
return new ModelAndView(createBusinessModel, retModel);
}else{
params.put("type", "BUSINESS_MODEL");
params.put("detailInfo", request.getParameter("detailInfo"));
params.put("loginId", userMap.get("LoginId"));
ServiceRequest serviceRequest = new ServiceRequest();
serviceRequest.setCurrentRequestObject(params);
serviceRequest.setRequestedServiceID("accountBusIndustryAction");
ServiceResponse serviceResponse = dispatchService(serviceRequest, WebContextNames.PAFA_AC);
Map<Object,Object> retModel = serviceResponse.getModel();
model.putAll(retModel);
OpptyUtils.output(JSONObject.fromMap(model), response);
}
return null;
}
/**
* 查询客户商业模式
* @param request
* @param arg1
* @return
*/
private ModelAndView queryBusinessModel(HttpServletRequest request,
HttpServletResponse arg1){
Map params = new HashMap();
Map model = new HashMap();
Map userMap = (Map) request.getSession().getAttribute("userProfile");
try {
params.put("accountId", request.getParameter("accountId"));
params.put("type", "BUSINESS_MODEL"); //商业模式标记
PageBean pager = CommonFunction.getPageBean(request);
pager.setPageSize(5);
params.put("pager", pager);
ServiceRequest serviceRequest = new ServiceRequest();
serviceRequest.setRequestedServiceID("accountBusIndustryAction");
serviceRequest.setCurrentRequestObject(params);
ServiceResponse serviceResponse = new ServiceResponse();
serviceResponse = dispatchService(serviceRequest,WebContextNames.PAFA_AC);
model = serviceResponse.getModel();
model.put("accountId", request.getParameter("accountId"));
model.put("loginId", userMap.get("LoginId"));
model.put("params", params);
List resultList=(List) model.get("resultList");
Integer count = new Integer(0);
if(resultList != null && resultList.size() > 0) {
count = new Integer(((BigDecimal) ((Map) resultList.get(0))
.get("totalRecordNum")).intValue());
pager.setTotalRecords(count.intValue());
}
model.put("pager", pager);
} catch (Exception e) {
LogUtil.error("查询客户商业模式出错-BondQueryRoleOrgModuleController", e);
}
return new ModelAndView(viewName, model);
}
private String viewName;
public String getViewName() {
return viewName;
}
public void setViewName(String viewName) {
this.viewName = viewName;
}
private String createBusinessModel;
public String getCreateBusinessModel() {
return createBusinessModel;
}
public void setCreateBusinessModel(String createBusinessModel) {
this.createBusinessModel = createBusinessModel;
}
}
6.Action代码
package com.pingan.ecpub.biz.action.bond.account;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.paic.pafa.app.biz.action.AbstractAction;
import com.paic.pafa.app.biz.service.BusinessServiceException;
import com.paic.pafa.app.dto.ServiceRequest;
import com.paic.pafa.app.dto.ServiceResponse;
import com.pingan.ecpub.biz.service.CommonService;
import com.pingan.ecpub.util.LogUtil;
/**
* 客户商业行业Action
* @author EX-LIUJUN517
*
*/
public class AccountBusIndustryAction extends AbstractAction {
private CommonService commonService;
public CommonService getCommonService() {
return commonService;
}
public void setCommonService(CommonService commonService) {
this.commonService = commonService;
}
public ServiceResponse perform(ServiceRequest request)
throws BusinessServiceException {
Map model = new HashMap();
ServiceResponse response = new ServiceResponse();
Map params = (Map)request.getCurrentRequestObject();
// 查询产品大类
try {
//新增
if("new".equals(params.get("disPath"))){
commonService.commonInsert("INSERT_CX_ACCNT_BUS_INDUSTRY", params);
//修改
}else if("update".equals(params.get("disPath"))){
String chengFlag = (String) params.get("chengFlag");
//修改提交
if("Y".equals(chengFlag)){
commonService.commonInsert("UPDATE_CX_ACCNT_BUS_INDUSTRY", params);
//修改初始化
}else{
List resultList = commonService.queryForList("QUERY_CX_ACCNT_BUS_INDUSTRY", params);
if(resultList.size()>0){
Map resultMap=(Map) resultList.get(0);
model.put("resultMap", resultMap);
}
}
}else if("delete".equals(params.get("disPath"))){
commonService.commonDelete("DELETE_CX_ACCNT_BUS_INDUSTRY", params);
//查询
}else{
List resultList = commonService.queryForList("QUERY_CX_ACCNT_BUS_INDUSTRY_LIST", params);
model.put("resultList", resultList);
}
model.put("ResultCode", "0");
} catch (Exception e) {
LogUtil.error("error",e);
model.put("ResultCode", "1");
}
response.setModel(model);
return response;
}
}
sql配置:
<!-- 新增 -->
<insert id="INSERT_CX_ACCNT_BUS_INDUSTRY" parameterClass="java.util.Map">
INSERT INTO SIEBEL.CX_ACCNT_BUS_INDUSTRY
(ID_ACCNT_BUS_INDUSTRY,
ACCOUNT_ID,
TYPE,
DETAIL_INFO,
CREATED_BY,
DATE_CREATED,
UPDATED_BY,
DATE_UPDATED)
values(
(SELECT UPPER(SIEBEL.ROW_ID_GENERATOR.NEXT_ROW_ID) FROM DUAL),
#accountId#,
#type#,
#detailInfo#,
#loginId#,
sysdate,
#loginId#,
sysdate
)
</insert>
<!-- 修改 -->
<update id="UPDATE_CX_ACCNT_BUS_INDUSTRY" parameterClass ="java.util.Map">
update siebel.CX_ACCNT_BUS_INDUSTRY t
set t.DETAIL_INFO = #detailInfo#,
t.DATE_UPDATED = sysdate,
t.UPDATED_BY = #loginId#
where t.ID_ACCNT_BUS_INDUSTRY = #accntBusIndustryId#
</update>
<!-- 查询 -->
<select id="QUERY_CX_ACCNT_BUS_INDUSTRY_LIST" resultClass="java.util.HashMap" parameterClass="java.util.HashMap">
select tmp.* from
(select tt.*,rownum num from
(SELECT T.ID_ACCNT_BUS_INDUSTRY "accntBusIndustryId",
T.ACCOUNT_ID "accountId",
T.DETAIL_INFO "detailInfo",
T.TYPE "type",
T1.LAST_NAME "lastName",
(select u.login from siebel.s_user u where u.row_id=T1.row_id) "loginName",
T1.row_id "loginId",
TO_CHAR(T.DATE_UPDATED,'YYYY-MM-DD HH24:MI') "dateUpdated",
TO_CHAR(T.DATE_UPDATED,'YYYY-MM-DD') "dateUpdatedStr",
(select t4.office_bldg_cd
from siebel.s_emp_per t4
where t4.row_id = T.CREATED_BY
and rownum = 1) "buName", <!-- 岗位 -->
COUNT(1) OVER() "totalRecordNum"
FROM CX_ACCNT_BUS_INDUSTRY T, SIEBEL.S_CONTACT T1,SIEBEL.S_ORG_EXT T3
WHERE T.UPDATED_BY = T1.ROW_ID
AND T3.row_id = (select T2.Bu_Id
from SIEBEL.S_POSTN T2
where T2.pr_emp_id = T1.row_id
<![CDATA[AND T2.NAME<>'DUMMY POSITION']]>
and rownum = 1)
and T.ACCOUNT_ID = #accountId#
<!--类型 -->
<isNotEmpty property="type">
and T.TYPE = #type# <!-- 类型 :行业地位(INDUSTRY_STATUS),商机模式(BUSINESS_MODEL) -->
</isNotEmpty>
ORDER BY T.DATE_UPDATED DESC
) tt
<isNotNull prepend="" property="pager">
<![CDATA[
where rownum<=(#pager.pageSize#+#pager.offset#)
]]>
</isNotNull>
) tmp
<isNotNull prepend="" property="pager">
<![CDATA[
where tmp.num>#pager.offset#
]]>
</isNotNull>
</select>
----------------------------------------
参考资料:
http://jsptags.com/tags/navigation/pager/index.jsp Pager-taglibs官网