SSH实现查询功能的完整操作代码

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

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'}
            ]
 })
});
var sm = new Ext.grid.CheckboxSelectionModel();
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
         }]);
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

 

{"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

<?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

	<!-- 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

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

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.增加树的结点的实现代码

function submitForm(){
	    Ext.Ajax.request({
		url :'../../ast/system/consumablesSave.action',  
		params : {
              'consumables.name':Ext.getCmp('name').getValue(),
              'consumables.parentConsumables.id': '1' //找到父结点的id
              },
        success : function(response) {
		var resText=Ext.util.JSON.decode(response.responseText);				
			if(resText.success){
				Ext.Msg.alert('提示', "保存成功!");
				storeConsumables.reload();
				addWin.hide();
			}else{
				Ext.Msg.alert('提示', "保存失败!");
				addWin.hide();
			}
        },
        failure : function(response) {
        	Ext.Msg.alert("提示","<font color='red'>服务器连接失败,请联系管理员!</font>");
        }
    });
}

 

你可能感兴趣的:(bean,struts,ssh,ext,配置管理)