flex+java增删改查(spring+jpa)简单例子

采用jpa+spring+flex技术实现整合的增删改查Demo 其中需要在tomcat中放入blazeds.war  ds-console.war samples.war 三个包。
flex部分代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

   <mx:Script >
   	<![CDATA[
   		import mx.controls.*;
   		import mx.events.ListEvent;
   		import mx.controls.dataGridClasses.*;
   		import mx.rpc.events.ResultEvent;
   		 
   		
   		private var usersid:int;
   		private var usersname:String;
   		private function dataInit(event:ResultEvent):void{
   			
   			DataGrid2.dataProvider=event.result;
   		}
   		private function addItem():void{
   			
   			var username:String =uiName.text;
   			s.save(username);
   			showdata();
   			
   		}
   		
   		
   		 private function delItem():void{       
   		    s.deleteuser(usersid);
   	        showdata();
   		 } 
   		
   		private function updateItem():void{
   			
   			 
   			 s.updateuser(usersid,uiName.text);
   			 showdata();
   		}
   		
   		private function showdata():void{
   			s.getList();
   		}
   		private function itemClick(e:ListEvent):void{
 
   			  var dat:Object=(e.target as DataGrid).selectedItem
   			  
   			  
   	   		for(var i:* in dat){
   			  	
   			  	if(i=="userid"){
   			  		usersid=dat[i]

   			  	}
   			  	if(i=="username"){
   			  		usersname=dat[i]
   			  		uiName.text=usersname;
   			  	}
   			  	
   			  }
             
   			 
   			
   		}
   	]]>
   </mx:Script>


   <mx:RemoteObject destination="save" id="s" result="dataInit(event)" endpoint="/firstFlex/messagebroker/amf" >
   	
   </mx:RemoteObject>
      <mx:DataGrid id="DataGrid2" itemClick="itemClick(event)"  width="430" y="10" x="10" height="208">
      	 <mx:columns>
      	     
      	 	 <mx:DataGridColumn headerText="ID" dataField="userid"/>
      	 	 <mx:DataGridColumn headerText="用户名" dataField="username"/>
      	 	
      	 </mx:columns>
      	
      </mx:DataGrid>

    <mx:TextInput id="uiName" x="10" y="288" width="150"/>

    <mx:Label x="10" y="271"  text="用户名:"/>
    
    <mx:Button click="addItem()" x="10" y="368" label="添加" width="150"/>
     <mx:Button click="updateItem()" x="190" y="368" label="修改" width="150"/>
    <mx:Button click="delItem()" x="360" y="368" label="删除" width="150"/>
    <mx:Button x="476" y="11" label="显示" click="showdata()"/>
    <mx:Button click="addItem()" x="10" y="368" label="添加" width="150"/>
	
</mx:Application>


其余代码见附件。
由于上传jar包工程太大  jar包请自己加载

你可能感兴趣的:(java,spring,tomcat,Flex,jpa)