SSH实现查询功能代码

1.extjs实现查询的基本界面及返回数据的界面search.js

Js代码 复制代码
  1. var storeGoods = new Ext.data.Store({       
  2.  id : 'baseStore',   
  3.  proxy : new Ext.data.HttpProxy({   
  4.     url : "../../ast/consumables/goodsSearch.action",   
  5.     method : "post"  
  6.    }),   
  7.  autoLoad : true,   
  8.  reader : new Ext.data.JsonReader({   
  9.   root : 'result',                 
  10.   totalProperty : 'totalCount'// 总记录数   
  11.   fields : [   
  12.             {name : 'goodscode',mapping:'goodscode'},   
  13.             {name : 'goodsbar',mapping:'goodsbar'}   
  14.             ]   
  15.  })   
  16. });  
var storeGoods = new Ext.data.Store({    
 id : 'baseStore',
 proxy : new Ext.data.HttpProxy({
    url : "../../ast/consumables/goodsSearch.action",
    method : "post"
   }),
 autoLoad : true,
 reader : new Ext.data.JsonReader({
  root : 'result',              
  totalProperty : 'totalCount', // 总记录数
  fields : [
            {name : 'goodscode',mapping:'goodscode'},
            {name : 'goodsbar',mapping:'goodsbar'}
            ]
 })
});
Js代码 复制代码
  1. var sm = new Ext.grid.CheckboxSelectionModel();  
var sm = new Ext.grid.CheckboxSelectionModel();
Js代码 复制代码
  1. var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),sm,   
  2.             {   
  3.              header : "货品编号",   
  4.              width : 100,   
  5.              dataIndex : "goodscode",   
  6.              align : "center",   
  7.              sortable : true  
  8.             },{   
  9.              header : "货品条码",   
  10.              width : 100,   
  11.              dataIndex : "goodsbar",   
  12.              align : "center",   
  13.              sortable : true  
  14.          }]);  
var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),sm,
            {
             header : "货品编号",
             width : 100,
             dataIndex : "goodscode",
             align : "center",
             sortable : true
            },{
             header : "货品条码",
             width : 100,
             dataIndex : "goodsbar",
             align : "center",
             sortable : true
         }]);
Js代码 复制代码
  1. var grid = new Ext.grid.GridPanel( {   
  2.         frame : true,   
  3.         stripeRows : true,   
  4.         region : "center",   
  5.         store : storeGoods,   
  6.         tbar : new Ext.Toolbar( {   
  7.             monitorResize : true,   
  8.             items : [   
  9.                 {   
  10.                     xtype: 'textfield',   
  11.                     name: 'searchfield',   
  12.                     id:'searchfield'  
  13.                    },   
  14.                 {   
  15.        
  16.                     cls : 'x-btn-text-icon',   
  17.                     text : "查   询",   
  18.                     handler : function() {   
  19.                         var search = Ext.getCmp("searchfield").getValue();   
  20.                         storeGoods.setBaseParam("searchModel.goodsname", search);   
  21.                         storeGoods.load();   
  22.                       },   
  23.                     scope : this  
  24.                 }]   
  25.     }),   
  26.     enableColumnMove : false,   
  27.     colModel : cm,   
  28.     viewConfig : {forceFit : true},   
  29.     sm : sm,   
  30.     bbar : new Ext.PagingToolbar({   
  31.                 pageSize : 18,   
  32.                 store : storeGoods,   
  33.                 displayInfo : true,   
  34.                 displayMsg : '显示第 {0} 条到 {1} 条记录,一共 {2} 条',   
  35.                 emptyMsg : "没有记录"  
  36.             })   
  37.     });   
  38. Ext.onReady(function(){   
  39.         var border = new Ext.Viewport({   
  40.             layout:'border',   
  41.             renderTo:Ext.getBody(),   
  42.             items:[{   
  43.                 region:'center',   
  44.                 split:true,   
  45.                 border:true,   
  46.                 layout:'border',   
  47.                 items:[grid]   
  48.             }]   
  49.         });        
  50. });  
var grid = new Ext.grid.GridPanel( {
		frame : true,
		stripeRows : true,
		region : "center",
		store : storeGoods,
		tbar : new Ext.Toolbar( {
			monitorResize : true,
			items : [
			    {
					xtype: 'textfield',
		            name: 'searchfield',
		            id:'searchfield'
				   },
				{
	
					cls : 'x-btn-text-icon',
					text : "查   询",
					handler : function() {
						var search = Ext.getCmp("searchfield").getValue();
						storeGoods.setBaseParam("searchModel.goodsname", search);
						storeGoods.load();
				      },
					scope : this
				}]
	}),
	enableColumnMove : false,
	colModel : cm,
	viewConfig : {forceFit : true},
	sm : sm,
	bbar : new Ext.PagingToolbar({
				pageSize : 18,
				store : storeGoods,
				displayInfo : true,
				displayMsg : '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
				emptyMsg : "没有记录"
			})
	});
Ext.onReady(function(){
		var border = new Ext.Viewport({
			layout:'border',
			renderTo:Ext.getBody(),
			items:[{
				region:'center',
				split:true,
				border:true,
				layout:'border',
				items:[grid]
			}]
		});		
});

 2.配置freemark的返回数据.ftl格式文件goodsList.ftl

 

Java代码 复制代码
  1. {"totalCount":"${count?c}","result":   
  2.     [   
  3.     <#list result as r>   
  4.         {   
  5.             "id":"${r.id!""}",   
  6.             "goodscode":"${r.goodscode!""}",   
  7.             "goodsbar":"${r.goodsbar!""}",   
  8.         }   
  9.         <#if r_has_next>,</#if>   
  10.     </#list>   
  11.     ]   
  12. }  
{"totalCount":"${count?c}","result":
	[
	<#list result as r>
		{
			"id":"${r.id!""}",
			"goodscode":"${r.goodscode!""}",
			"goodsbar":"${r.goodsbar!""}",
	 	}
		<#if r_has_next>,</#if>
	</#list>
	]
}

3.配置struts实现goodsSearch的映射struts-consumables.xml

Java代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <!DOCTYPE struts PUBLIC    
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">   
  5.   
  6. <struts>   
  7.        
  8.     <package name="kingee-ast-consumables" extends="kingee_ast_default" namespace="/ast/consumables">   
  9.            
  10.         <!-- 查询 action -->   
  11.         <action name="goodsSearch" class="goodsGridSearchCore">   
  12.             <result type="freemarker">/consumables/search/goodsList.ftl</result>   
  13.         </action>   
  14.                    
  15.     </package>   
  16.   
  17. </struts>  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC 
	"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
	"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	
	<package name="kingee-ast-consumables" extends="kingee_ast_default" namespace="/ast/consumables">
		
		<!-- 查询 action -->
		<action name="goodsSearch" class="goodsGridSearchCore">
		    <result type="freemarker">/consumables/search/goodsList.ftl</result>
		</action>
				
	</package>

</struts>

 4.配置spring的配置文件applicationContext-search.xml

Java代码 复制代码
  1. <!-- role searchCore -->   
  2.     <bean id="goodsSearchModel" class="com.kingee.ast.consumables.search.model.ConGoodsSearchModel" scope="prototype"></bean>   
  3.     <bean id="goodsSearchProvider" class="com.kingee.ast.consumables.search.provider.ConGoodsSearchProvider" >   
  4.             <property name="hibernateTemplate" ref="astNoCacheHibernateTemplate"></property>   
  5.     </bean>   
  6.        
  7.     <bean id="goodsGridSearchCore" class="com.joyoung.framework.search.GridSearchCore" scope="prototype">   
  8.             <property name="searchModel" ref="goodsSearchModel"></property>   
  9.             <property name="searchProvider" ref="goodsSearchProvider"></property>   
  10.     </bean>     
	<!-- role searchCore -->
		<bean id="goodsSearchModel" class="com.kingee.ast.consumables.search.model.ConGoodsSearchModel" scope="prototype"></bean>
		<bean id="goodsSearchProvider" class="com.kingee.ast.consumables.search.provider.ConGoodsSearchProvider" >
				<property name="hibernateTemplate" ref="astNoCacheHibernateTemplate"></property>
		</bean>
		
		<bean id="goodsGridSearchCore" class="com.joyoung.framework.search.GridSearchCore" scope="prototype">
		    	<property name="searchModel" ref="goodsSearchModel"></property>
		    	<property name="searchProvider" ref="goodsSearchProvider"></property>
		</bean> 	

 

5.写出searchModel的实现代码ConGoodsSeachModel.java

Java代码 复制代码
  1. public class ConGoodsSearchModel implements SearchModel{   
  2.     private String goodsname;   
  3.     @Override  
  4.     public Map<String, ?> toMap() {   
  5.         Map<String,String> map=new HashMap<String, String>();   
  6.         map.put("goodsname", goodsname);   
  7.         return map;   
  8.     }   
  9.     public String getGoodsname() {   
  10.         return goodsname;   
  11.     }   
  12.     public void setGoodsname(String goodsname) {   
  13.         this.goodsname = goodsname;   
  14.     }   
  15. }  
public class ConGoodsSearchModel implements SearchModel{
	private String goodsname;
	@Override
	public Map<String, ?> toMap() {
		Map<String,String> map=new HashMap<String, String>();
		map.put("goodsname", goodsname);
		return map;
	}
	public String getGoodsname() {
		return goodsname;
	}
	public void setGoodsname(String goodsname) {
		this.goodsname = goodsname;
	}
}

 

6.写出searchProvider的实现代码ConGoodsSearchProvider.java

Java代码 复制代码
  1. public class ConGoodsSearchProvider extends HibernateSearchProvider{   
  2.     @Override  
  3.     protected DetachedCriteria getDetachedCriteria(Map<String, ?> map) {   
  4.         DetachedCriteria detachedCriteria=DetachedCriteria.forClass(ConGoods.class,"conGoods");        
  5.         if(null !=map.get("goodsname") && !"".equals(map.get("goodsname"))){   
  6.             detachedCriteria.add(Restrictions.or(Restrictions.like("goodsname""%"+map.get("goodsname")+"%"),   
  7.                                                  Restrictions.or(Restrictions.like("goodscode""%"+map.get("goodsname")+"%"),   
  8.                                                                  Restrictions.like("goodsstyle","%"+map.get("goodsname")+"%"))));   
  9.         }   
  10.         detachedCriteria.add(Restrictions.eq("deleted"false));   
  11.         return detachedCriteria;   
  12.     }   
  13. }  
public class ConGoodsSearchProvider extends HibernateSearchProvider{
	@Override
	protected DetachedCriteria getDetachedCriteria(Map<String, ?> map) {
		DetachedCriteria detachedCriteria=DetachedCriteria.forClass(ConGoods.class,"conGoods");		
		if(null !=map.get("goodsname") && !"".equals(map.get("goodsname"))){
			detachedCriteria.add(Restrictions.or(Restrictions.like("goodsname", "%"+map.get("goodsname")+"%"),
					                             Restrictions.or(Restrictions.like("goodscode", "%"+map.get("goodsname")+"%"),
					            		                         Restrictions.like("goodsstyle","%"+map.get("goodsname")+"%"))));
		}
		detachedCriteria.add(Restrictions.eq("deleted", false));
		return detachedCriteria;
	}
}

 其中ConGoods.class实现的是,找出货品的pojo实体类,然后通过hibernate的配置文件,查找数据库中对应的表格数据

  7.增加树的结点的实现代码

Java代码 复制代码
  1. function submitForm(){   
  2.         Ext.Ajax.request({   
  3.         url :'../../ast/system/consumablesSave.action',     
  4.         params : {   
  5.               'consumables.name':Ext.getCmp('name').getValue(),   
  6.               'consumables.parentConsumables.id''1' //找到父结点的id   
  7.               },   
  8.         success : function(response) {   
  9.         var resText=Ext.util.JSON.decode(response.responseText);                   
  10.             if(resText.success){   
  11.                 Ext.Msg.alert('提示'"保存成功!");   
  12.                 storeConsumables.reload();   
  13.                 addWin.hide();   
  14.             }else{   
  15.                 Ext.Msg.alert('提示'"保存失败!");   
  16.                 addWin.hide();   
  17.             }   
  18.         },   
  19.         failure : function(response) {   
  20.             Ext.Msg.alert("提示","<font color='red'>服务器连接失败,请联系管理员!</font>");   
  21.         }   
  22.     });   
  23. }  

你可能感兴趣的:(bean,struts,ext,prototype,ssh)