当前位置:   article > 正文

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

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

 

  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. }

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

  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. <struts>
  6. <package name="kingee-ast-consumables" extends="kingee_ast_default" namespace="/ast/consumables">
  7. <!-- 查询 action -->
  8. <action name="goodsSearch" class="goodsGridSearchCore">
  9. <result type="freemarker">/consumables/search/goodsList.ftl</result>
  10. </action>
  11. </package>
  12. </struts>

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

  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. <bean id="goodsGridSearchCore" class="com.joyoung.framework.search.GridSearchCore" scope="prototype">
  7. <property name="searchModel" ref="goodsSearchModel"></property>
  8. <property name="searchProvider" ref="goodsSearchProvider"></property>
  9. </bean>

 

5.写出searchModel的实现代码ConGoodsSeachModel.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. }

 

6.写出searchProvider的实现代码ConGoodsSearchProvider.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. }

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

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

  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. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/185270
推荐阅读
相关标签
  

闽ICP备14008679号