spring mvc與ligerUI 架構 學習筆記 之 增刪改查

Demo效果界面:

 

開發架構:

LigerUI+Spring MVC+Hibernate+JSON+jquery

 

  1:LigerUI學習知識點總計

(1):關於Lgerui js庫的引入,在學習階段,可以將全部的庫導入,減少每次考慮導入哪些JS的學習成本。

    <link href="<%=basePath%>/script/jquery/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="<%=basePath%>/script/jquery/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="<%=basePath%>/script/jquery/lib/ligerUI/js/core/base.js" type="text/javascript"></script> 
    <script src="<%=basePath%>/script/jquery/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
    <script src="<%=basePath%>/script/role.js" type="text/javascript"></script>
 

2grid內容修改後,需要調用endEdit方法提交修改,這時候通過getData得到的數據纔是最新的數據。

    	   $grid.endEdit();
            var dataArray = $grid.getData();

 

2:JQUERY學習知識點總結

(1):jquery中遍歷數組(each),及往數組中添加對象的方法(push)

		        $.each(dataArray, function (index, entity) {
		        	var role=new Role(entity.id,entity.name,entity.remark);
		        	data.push(role.toString());
		        });
(2):JS中創建對象,及對象中創建方法
function  Role(id,name,remark) {
	this.id=id;
	this.name=name;
	this.remark=remark;
	this.toString=function () {
		return "id:"+id+";name:"+this.name+";remark:"+remark;
	}
}
(3):JS中 Ajax的數據實現流程
	    		var ids=[];	
		        $.each(selected, function (index, entity) {
		        	ids.push(entity.id);
		        });
		        $.ajax({
		            url: jsCommonPath+'/roleController.do?method=deleteList',
		            data: 'ids='+ids,
		            dataType: 'json',
		            type: 'post',
		            success: function (result)
		            {	
		            	$grid.loadData();
		            	$.ligerDialog.warn('刪除成功');
		            }
		        });		
    		}});
4:學習Filebug 和Post數據的查看辦法,及JS斷點的方法 
 

5:掌握POST發送一個字符串數組的方法,這時後臺可以用一個數組接收array參數的值;

掌握POST傳送一個List的辦法,需要將對象數組拼裝成字符串,在後臺接收字符串再解析成對象數組。

 

	    		var data=[];	
		        $.each(dataArray, function (index, entity) {
		        	var role=new Role(entity.id,entity.name,entity.remark);
		        	data.push(role.toString());
		        });
            
	        $.ajax({
	            url: jsCommonPath+'/roleController.do?method=saveList',
	            data: "Rows="+data,
	            dataType: 'json',
	            type: 'post',
	            success: function (result)
	            {	
	            	$grid.loadData();
	            	$.ligerDialog.success('保存成功');
	            },
                error: function (message) {
                   $.ligerDialog.error(message);
                }	            
	        });		

 

 掌握POST傳送一個對象的方法,能將對象解析成屬性和值的組合發到POST數據包中

 

Spring mvc 的學習總結
1:在配置文件中定義視圖時,Order屬性可以定義 視圖的 匹配順序。

     <bean id="viewResolver1" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass">
			<value>org.springframework.web.servlet.view.JstlView</value>
		</property>
		<property name="prefix">
			<value>/jsp/</value>
		</property>
		<property name="suffix">
			<value>.jsp</value>
		</property>
		<property name="contentType">
			<value>text/html;charset=UTF8</value>
		</property>
		<property name="order">
			<value>2</value>
		</property> 
	</bean>
2:掌握 註解的使用方法,RequestMapping 用來定義URL和Action的匹配,RequestParam用來定義從request中接收參數,掌握 ModelAndView傳送頁面和傳送JSON數據的方法。
	@RequestMapping(params ="method=queryView") 
	public ModelAndView querySpringView(@RequestParam("page")int page,@RequestParam("pagesize")int pagesize) {		
		PagingBean pagingBean=new PagingBean(pagesize,page);
		QueryResult queryResult=roleService.queryObjList(new FilterInfo(), pagingBean);
		List<RoleBean> roleBeanList=queryResult.getResultList();
		Map resultMap=new HashMap();
		resultMap.put("Rows", roleBeanList);
		resultMap.put("Total", queryResult.getTotalRecordNumber());
		return new ModelAndView("ajax",resultMap);
	}
3:掌握參數中接收數組的方法,這個與上面 刪除的JS方法對應 
	@RequestMapping(params ="method=deleteList") 
	public ModelAndView deleteObjList(@RequestParam("ids") String[] ids) {
		roleService.deleteObj(ids);
		return new ModelAndView("ajax","0","0");
	}	

 

4: XmlViewResolver用於將其他XML中的視圖包含進來

	 <bean name="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver" >
	    <property name="order" value="1"/>
		<property name="location" value="classpath:config/mvc/views.xml"/>
    </bean>


 

以上源代碼已經備份到以下路徑,幷包含一個POST傳送數據的測試文檔

F:\學習資料\項目備份\springLigerFramework0524.zip


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章