`
79343654
  • 浏览: 45927 次
  • 性别: Icon_minigender_1
  • 来自: 太原
社区版块
存档分类
最新评论
阅读更多

java 代码:

 

 

package com.topdt.message.web.action;

 

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

import java.util.Map;

 

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.apache.struts2.convention.annotation.Action;

import org.apache.struts2.convention.annotation.Namespace;

import org.apache.struts2.convention.annotation.ParentPackage;

import org.apache.struts2.convention.annotation.Result;

import org.apache.struts2.interceptor.SessionAware;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Controller;

 

import com.opensymphony.xwork2.ActionSupport;

import com.topdt.message.entity.Business;

import com.topdt.message.service.BusinessManager;

 

@Controller

@Scope("prototype")

@ParentPackage(value = "gloab-package")

@Namespace(value = "/message")

@Action(value = "business", results = {

@Result(name="query",type="json"),

@Result(name="show",location="/message/business/business_list.jsp")

})

public class BusinessAction extends ActionSupport implements SessionAware {

 

private static final long serialVersionUID = 1L;

 

private static final Log log = LogFactory.getLog(BusinessAction.class);

private List<Business> gridModel;

private Integer rows;

private Integer page;

private String sord;

private String sidx;

private String searchField;

private String searchString;

private Integer totalrows;

private String searchOper;

private Integer total;

private Integer records;

private boolean loadonce;

private List<Business> myCustomers;

@Autowired

private BusinessManager businessManager;

public BusinessAction() {

this.rows = Integer.valueOf(0);

 

this.page = Integer.valueOf(0);

 

this.total = Integer.valueOf(0);

 

this.records = Integer.valueOf(0);

 

this.loadonce = false;

}

public String show() {

return "show";

}

 

public String query() {

this.myCustomers = businessManager.query();

if ((this.sord != null) && (this.sord.equalsIgnoreCase("asc"))) {

Collections.sort(this.myCustomers);

}

if ((this.sord != null) && (this.sord.equalsIgnoreCase("desc"))) {

Collections.sort(this.myCustomers);

Collections.reverse(this.myCustomers);

}

 

this.records = businessManager.getCustomersCount(this.myCustomers);

 

if (this.totalrows != null) {

this.records = this.totalrows;

}

 

int to = this.rows.intValue() * this.page.intValue();

 

int from = to - this.rows.intValue();

 

if (to > this.records.intValue())

to = this.records.intValue();

 

if (this.loadonce) {

if ((this.totalrows != null) && (this.totalrows.intValue() > 0)) {

setGridModel(this.myCustomers.subList(0, this.totalrows

.intValue()));

} else {

setGridModel(this.myCustomers);

}

 

} else if ((this.searchString != null) && (this.searchOper != null)) {

Long id = new Long(this.searchString);

if (this.searchOper.equalsIgnoreCase("eq")) {

log.debug("search id equals " + id);

List cList = new ArrayList();

Business business = businessManager.findById(this.myCustomers, id);

if (business != null)

cList.add(business);

 

setGridModel(cList);

} else if (this.searchOper.equalsIgnoreCase("ne")) {

log.debug("search id not " + id);

setGridModel(businessManager.findNotById(this.myCustomers, id, from, to));

} else if (this.searchOper.equalsIgnoreCase("lt")) {

log.debug("search id lesser then " + id);

setGridModel(businessManager.findLesserAsId(this.myCustomers, id, from, to));

} else if (this.searchOper.equalsIgnoreCase("gt")) {

log.debug("search id greater then " + id);

setGridModel(businessManager.findGreaterAsId(this.myCustomers, id, from, to));

}

} else {

setGridModel(businessManager.getCustomers(this.myCustomers, from, to));

}

 

this.total = Integer.valueOf((int) Math.ceil(this.records.intValue()

/ this.rows.intValue()));

return "query";

}

 

public String getJSON() {

return query();

}

 

public Integer getRows() {

return this.rows;

}

 

public void setRows(Integer rows) {

this.rows = rows;

}

 

public Integer getPage() {

return this.page;

}

 

public void setPage(Integer page) {

this.page = page;

}

 

public Integer getTotal() {

return this.total;

}

 

public void setTotal(Integer total) {

this.total = total;

}

 

public Integer getRecords() {

return this.records;

}

 

public void setRecords(Integer records) {

this.records = records;

 

if ((this.records.intValue() > 0) && (this.rows.intValue() > 0)) {

this.total = Integer.valueOf((int) Math.ceil(this.records

.intValue()

/ this.rows.intValue()));

} else {

this.total = Integer.valueOf(0);

}

}

 

public List<Business> getGridModel() {

return this.gridModel;

}

 

public void setGridModel(List<Business> gridModel) {

this.gridModel = gridModel;

}

 

public String getSord() {

return this.sord;

}

 

public void setSord(String sord) {

this.sord = sord;

}

 

public String getSidx() {

return this.sidx;

}

 

public void setSidx(String sidx) {

this.sidx = sidx;

}

 

public void setSearchField(String searchField) {

this.searchField = searchField;

}

 

public void setSearchString(String searchString) {

this.searchString = searchString;

}

 

public void setSearchOper(String searchOper) {

this.searchOper = searchOper;

}

 

public void setLoadonce(boolean loadonce) {

this.loadonce = loadonce;

}

 

public void setTotalrows(Integer totalrows) {

this.totalrows = totalrows;

}

public void setSession(Map<String, Object> session) {

}

}

 

 

 

package com.topdt.message.service;

 

import java.util.ArrayList;

import java.util.Hashtable;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

 

 

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

 

import com.topdt.message.dao.BusinessDao;

import com.topdt.message.entity.Business;

import com.topdt.message.entity.Product;

 

 

@Service

@Transactional(readOnly = false)

public class BusinessManager {

private static Map<Long, Product> MAP_ID = new Hashtable<Long, Product>();

private static Map<String, Product> MAP_CODE = new Hashtable<String, Product>();

@Autowired

private BusinessDao businessDao;

@Transactional(readOnly = true)

public List<Business> query() {

return  businessDao.queryAll();

}

public static List<Business> getCustomers(List<Business> list,

int from, int to) {

return list.subList(from, to);

}

 

public static Business findById(List<Business> list, Long id) {

for (Iterator i$ = list.iterator(); i$.hasNext();) {

Business business = (Business) i$.next();

if (business.getBusinessId()== id)

return business;

}

return null;

}

 

public static List<Business> findNotById(List<Business> list, Long id,

int from, int to) {

List sResult = new ArrayList();

 

for (Iterator i$ = list.iterator(); i$.hasNext();) {

Business Business = (Business) i$.next();

 

if (Business.getBusinessId() != id)

sResult.add(Business);

}

 

return sResult.subList(from, to);

}

 

public static List<Business> findGreaterAsId(List<Business> list,

Long id, int from, int to) {

List sResult = new ArrayList();

 

for (Iterator i$ = list.iterator(); i$.hasNext();) {

Business Business = (Business) i$.next();

 

if (Business.getBusinessId() > id)

sResult.add(Business);

}

 

return sResult.subList(from, to);

}

 

public static List<Business> findLesserAsId(List<Business> list,

Long id, int from, int to) {

List sResult = new ArrayList();

 

for (Iterator i$ = list.iterator(); i$.hasNext();) {

Business Business = (Business) i$.next();

if (Business.getBusinessId() < id)

sResult.add(Business);

}

 

return sResult.subList(from, to);

}

 

public static Integer getCustomersCount(List<Business> list) {

return Integer.valueOf(list.size());

}

 

public BusinessDao getBusinessDao() {

return businessDao;

}

 

public void setBusinessDao(BusinessDao businessDao) {

this.businessDao = businessDao;

}

}



html代码:


<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>业务列表</title>
<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<!-- end no cache headers -->
<sj:head locale="zh-CN" />
</head>
<body style="margin:10px;padding:0px;">
    <s:url id="editurl" action="business!query"/>
    <s:url id="busGrid" action="business!query"/>
    <sjg:grid
    id="busTable"
    caption="业务列表"
    dataType="json"
    href="%{busGrid}"
    pager="true"
    navigator="true"
    navigatorSearchOptions="{sopt:['eq','ne','lt','gt']}"
    navigatorAddOptions="{height:280,reloadAfterSubmit:true}"
    navigatorEditOptions="{height:280,reloadAfterSubmit:false}"
    navigatorEdit="false"
    navigatorView="false"
    navigatorDelete="true"
    navigatorDeleteOptions="{height:280,reloadAfterSubmit:true}"
    navigatorExtraButtons="{
    seperator: { 
    title : 'seperator'  
    }, 
    hide : { 
    title : 'Show/Hide', 
    icon: 'ui-icon-wrench', 
    topic: 'showcolumns'
    },
    alert : { 
    title : 'Alert', 
    onclick: function(){ alert('Grid Button clicked!') }
    }
    }"
    gridModel="gridModel"
    rowList="10,15,20"
    rowNum="15"
    editurl="%{editurl}"
    editinline="true"
    onSelectRowTopics="rowselect"
    onEditInlineSuccessTopics="oneditsuccess"
    viewrecords="true"
    >
    <sjg:gridColumn width="40"name="businessId" index="businessId" align="right" title="业务ID" formatter="integer" sortable="false"/>
    <sjg:gridColumn width="100"name="businessName" index="businessName"  title="业务名称" sortable="false"/>
    <sjg:gridColumn width="100"name="shortName" index="shortName" title="业务简称" sortable="false"/>
    <sjg:gridColumn width="100"name="businessCatalog" index="businessCatalog" title="业务分类" sortable="false"/>
    <sjg:gridColumn width="100"name="businessType" index="businessType" title="业务类型" sortable="false"/>
    <sjg:gridColumn width="100"name="businessCode" index="businessCode" title="业务代码" sortable="false"/>
    <sjg:gridColumn width="100"name="modelCode" index="modelCode" title="模型编码" sortable="false"/>
    <sjg:gridColumn width="100"name="ownerId" index="ownerId" title="业务属主" sortable="false"/>
    <sjg:gridColumn width="100"name="resourceId" index="resourceId" title="服务类型" sortable="false"/>
    <sjg:gridColumn width="100"name="serviceType" index="serviceType" title="服务资源" sortable="false"/>
    </sjg:grid>
</body>
</html>



分享到:
评论

相关推荐

    struts2-jquery-plugin-3.1.0.jar

    struts2-jquery-plugin-3.1.0.jar

    struts2-jquery-plugin-2.0.0

    struts2-jquery-plugin-2.0.0 struts2-jquery-plugin-2.0.0 struts2-jquery-plugin-2.0.0

    struts2-jquery-plugin插件3.3.3

    最新的struts2-jquery-plugin插件3.3.3,包括jquery-ui和grid,使用标签实现。

    struts2-jquery-plugin使用手册,自己写的

    - 可以参考官方文档或者提供的示例代码学习如何使用Struts2-jQuery-Plugin。博主的博文链接(https://79343654.iteye.com/blog/1327488)可能包含更多实战经验。 - 在实际开发中,使用浏览器的开发者工具(如...

    struts-api.chm + struts-tags.chm 原版

    struts-api.chm + struts-tags.chm 原版struts-api.chm + struts-tags.chm 原版struts-api.chm + struts-tagsstruts-api.chm + struts-tags.chm 原版struts-api.chm + struts-tags.chm 原版struts-api.chm + struts-...

    struts2-jquery-plug ShowCase

    首先,`struts2-jquery-grid-showcase-3.3.0.zip`可能包含一个基于Struts2的jQuery Grid示例。jQuery Grid是一个功能强大的表格组件,它可以展示大量数据,并提供排序、分页、搜索和编辑等功能。在Struts2应用中使用...

    struts-tags.tld

    struts-tags.tld struts-tags.tldstruts-tags.tld struts-tags.tld struts-tags.tld

    struts-config.xml struts标准配置文件 struts-config

    struts-config.xml struts标准配置文件 struts-config

    struts-taglib-1.3.8.jar

    struts-taglib-1.3.8.jar struts-taglib-1.3.8.jar

    struts2-jquery-plugin

    struts2 jquery plugin ,学习struts2 ,又希望在其中使用Jquery的朋友,不妨看看

    struts2-jquery-grid-plugin-3.5.1.jar

    struts2-jquery-grid-plugin-3.5.1.jar 此jar包适合于struts2框架,一标签的形式实现grid插件,不过目前网络上此插件中文文档较少。

    struts2-jquery插件

    struts2-jquery插件源码。版本号3.0.1

    struts2-jquery-plugin-3_7_1

    struts2-jquery-plugin jar文件

    struts-core-1.3.8-API文档-中文版.zip

    赠送jar包:struts-core-1.3.8.jar; 赠送原API文档:struts-core-1.3.8-javadoc.jar; 赠送源代码:struts-core-1.3.8-sources.jar; 赠送Maven依赖信息文件:struts-core-1.3.8.pom; 包含翻译后的API文档:struts...

    jakarta-struts-1.1.zip_jakarta-Struts-1_jakarta-struts 1_jakarta

    总的来说,"jakarta-struts-1.1.zip"包含的资源对于学习和理解早期Java Web开发,尤其是Struts框架的运作机制非常有价值。通过查阅其中的API文档,开发者可以深入理解如何使用Struts来构建高效、可维护的Web应用。...

    struts2-core.jar

    struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...

    struts-2.3.4笔记

    学习 Struts 2.3.4 包含的这些知识点,有助于开发者更好地理解和构建基于 MVC 架构的 Java Web 应用程序。通过阅读提供的"上课日志",你可以深入学习每个概念的实际应用和示例,从而提升你的开发技能。

    struts-2.3.7-all

    struts-2.3.7-all jar包

    struts-spring-other-lib 等jar包

    struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-...

    struts-1.3.8-all.zip

    - **struts-core.jar**、**struts-el.jar**、**struts-faces.jar**等:特定功能的扩展库,如支持EL(Expression Language)和JSF(JavaServer Faces)。 使用Struts 1.3.8时,开发者需要配置web.xml和struts-config...

Global site tag (gtag.js) - Google Analytics