1. 程式人生 > >整合框架 javaweb開發平臺ssmy_m(與程式碼生成) java struts2 mybatis spring maven jquery

整合框架 javaweb開發平臺ssmy_m(與程式碼生成) java struts2 mybatis spring maven jquery

 

本頁地址 http://blog.csdn.net/lpy3654321/article/details/31841573

 

 

         專案設想,在專案開發中,我們的開發人員大多數時間都在重複開發 同樣的關鍵字,同樣的語法. 但就在這樣的情況下還會經常發生語法的錯誤,而且每個開發人員的程式碼風格不同. 其他人員閱讀困難.新人的學習成本也會增加.

         這些問題會浪費很多時間,也會影響到開發人員的心情,和程式質量. 由這些問題我想的解決方法是 <程式碼生成工具> . 程式碼生成可以解決上述問題,加強約定. 對於普通CRUD的開發效率可以提升50%以上,錯誤率幾乎為0 , 是專案系統的開發利器.

 

 

 

 

程式碼生成 程式碼生成工具

自己寫的開發平臺ssmy_m 與程式碼生成 ,struts2 mybatis spring maven jquery jqgrid jqueryui

有問題請留言,或QQ110146324

最下面有生成出來的程式碼

SVN上的程式碼基礎功能已經都有了.美工沒弄,有需要的自己改吧.

在/ssmy_m/src/main/webapp/common/include_com.jsp裡引用.否則程式碼生成會有影響

 

DEMO:

ssmy開發框架SSMy
http://ssmy_m.goodthink.wang
ssmy框架的程式碼生成工具

http://generate_m.goodthink.wang

generate_m生成的程式碼示例 https://download.csdn.net/download/lpy3654321/8438605


 

  • 開發平臺

 

svn: 

https://m2.svnspot.com/lpy3654321.ssmy_m/

 

帳號:guest112233

密碼:guest112233

也可以到 http://code.svnspot.com 註冊

開發平臺頁面 :右鍵新視窗開啟圖片可以放大

最下面有生成出來的程式碼

 




 

 

  • 程式碼生成

 

svn: 

https://m2.svnspot.com/lpy3654321.ssmy_generate_m/

 

帳號:guest112233

密碼:guest112233

也可以到 http://code.svnspot.com 註冊

 

 

通過過資料庫表生成BEAN  action servce dao xml js jsp 

修改dbConfigs.xml檔案,可配置生成的資料庫(啟動修改也可以,不需要重啟)

http://127.0.0.1:8080/generate_m

下載zip後,解壓,複製SRC 然後直接貼上到myeclipse 專案裡

<?xml version="1.0" encoding="UTF-8"?>
<!-- 用於生成資料庫的配置檔案 -->
<dbConfigs>

	<dbConfig id="localMysql"><!-- 配置名稱 -->
		<url>jdbc:mysql://localhost:3306/ssmy</url><!-- url -->
		<username>root</username><!-- </username> -->
		<password>root</password><!-- password -->
		<driverClass>com.mysql.jdbc.Driver</driverClass><!-- driverClass -->
	</dbConfig>
	
	<dbConfig id="localOracle">
		<url>jdbc:oracle:thin:@localhost:1521:orcl</url>
		<username>ssmy</username>
		<password>ssmy</password>
		<driverClass>oracle.jdbc.driver.OracleDriver</driverClass>
	</dbConfig>
	
	<dbConfig id="dsd_zjk">
		<url>jdbc:oracle:thin:@192.168.3.34:1521:orcl</url>
		<username>dsd_zjk</username>
		<password>dsd_zjk</password>
		<driverClass>oracle.jdbc.driver.OracleDriver</driverClass>
	</dbConfig>
	
</dbConfigs>

 

程式碼生成頁面:右鍵新視窗開啟圖片可以放大

 

 

 

 

"專案基本WEB層名稱空間"  和  "模組WEB層名稱空間"   這兩個input會決定Struts2的名稱空間和JS的引用路徑

 

<struts>
	<package name="com.liupengyuan.framework.pageView.action.PageViewAction" extends="struts-default" namespace="/framework/pageView">

		<action name="pageView_*"
				class="pageViewAction"
				method="{1}">
		</action>
		
		<action name="pageView">
			<result>/framework/pageView/pageView.jsp</result>
		</action>

	</package>
</struts>

 

 

 

 

 

 

 

  • 程式碼目錄:

 

 

 

  • Zip包目錄:

 

 

 

  • HTML JS 程式碼

pageView.jsp:

<%@ page language="java" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>記錄網路訪問量</title>
    <%@ include file="/common/include_com.jsp"%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="${pageContext.request.contextPath}/jsp/moduleWeb/pageView/js/pageView.js"></script>
    <!--<script src="js/pageView.js"></script>-->
	
  </head>
<body>

	<div class="ui-layout-north">
		<div class="navbar"><font size="2" > 當前操作:記錄網路訪問量</font></div>
	</div>
	
	<div class="ui-layout-center">
<!--	<div class="title_level1">查詢</div> -->
		<div class="formarea">
			<form id="pageViewSearchForm">
			<fieldset>
			<legend style="margin-left: 10px;">查詢</legend>

				<table>
					<tr>
						<td style="width:150px;" align="right" ><label for="requestIp">使用者IP:</label></td>
						<td>
							<div class="input">
								<input type="text" name="requestIp"  size="40"  />
							</div>
						</td>
						<td style="width:150px;" align="right" ><label for="session">記錄會話ID:</label></td>
						<td>
							<div class="input">
								<input type="text" name="session"  size="40"  />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:150px;" align="right" ><label for="module">訪問的模組:</label></td>
						<td>
							<div class="input">
								<input type="text" name="module"  size="40"  />
							</div>
						</td>
						<td style="width:150px;" align="right" ><label for="visitTime">訪問時間:</label></td>
						<td>
							<div class="input">
								<input type="text" name="visitTime" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="40"  />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:150px;" align="right" ><label for="visitCount">訪問數量:</label></td>
						<td>
							<div class="input">
								<input type="text" name="visitCount"  size="40"  />
							</div>
						</td>
					</tr>
				</table>
			</fieldset>
			</form>
			<div class="buttons">
				<button id="searchB">查詢</button>
				<button id="resetB">清空</button>
			</div>
		</div>		
		<div class="toolbar">
			<button id="addB">增加</button>
			<button id="editB">修改</button>
			<button id="deleteB">刪除</button>
		</div>
		<table id="pageViewTable"></table>
	</div>
	<div id="pageViewAddOrEditForm">
		<div class="formarea">
			<form id="pageViewForm" type="ajax">

				<input type="hidden" id="id" name="id"/>
				<table>
					<tr>
						<td style="width:70px;" align="right" ><label for="requestIp">使用者IP:</label></td>
						<td>
							<div class="input">
								<input type="text" id="requestIp" name="requestIp"  class="validate[maxSize[50] ] "  size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="session">記錄會話ID:</label></td>
						<td>
							<div class="input">
								<input type="text" id="session" name="session"  class="validate[maxSize[100] ] "  size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="module">訪問的模組:</label></td>
						<td>
							<div class="input">
								<input type="text" id="module" name="module"  class="validate[maxSize[100] ] "  size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="visitTime">訪問時間:</label></td>
						<td>
							<div class="input">
								<input type="text" id="visitTime" name="visitTime"  class="Wdate " onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="visitCount">訪問數量:</label></td>
						<td>
							<div class="input">
								<input type="text" id="visitCount" name="visitCount"  class="validate[maxSize[10] ] "  size="40" />
							</div>
						</td>
					</tr>
				</table>

			</form>
		</div>
	</div>
</body>
</html>
java" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>記錄網路訪問量</title>
    <%@ include file="/common/include_com.jsp"%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="${pageContext.request.contextPath}/jsp/moduleWeb/pageView/js/pageView.js"></script>
    <!--<script src="js/pageView.js"></script>-->
	
  </head>
<body>

	<div class="ui-layout-north">
		<div class="navbar"><font size="2" > 當前操作:記錄網路訪問量</font></div>
	</div>
	
	<div class="ui-layout-center">
<!--	<div class="title_level1">查詢</div> -->
		<div class="formarea">
			<form id="pageViewSearchForm">
			<fieldset>
			<legend style="margin-left: 10px;">查詢</legend>

				<table>
					<tr>
						<td style="width:150px;" align="right" ><label for="requestIp">使用者IP:</label></td>
						<td>
							<div class="input">
								<input type="text" name="requestIp"  size="40"  />
							</div>
						</td>
						<td style="width:150px;" align="right" ><label for="session">記錄會話ID:</label></td>
						<td>
							<div class="input">
								<input type="text" name="session"  size="40"  />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:150px;" align="right" ><label for="module">訪問的模組:</label></td>
						<td>
							<div class="input">
								<input type="text" name="module"  size="40"  />
							</div>
						</td>
						<td style="width:150px;" align="right" ><label for="visitTime">訪問時間:</label></td>
						<td>
							<div class="input">
								<input type="text" name="visitTime" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="40"  />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:150px;" align="right" ><label for="visitCount">訪問數量:</label></td>
						<td>
							<div class="input">
								<input type="text" name="visitCount"  size="40"  />
							</div>
						</td>
					</tr>
				</table>
			</fieldset>
			</form>
			<div class="buttons">
				<button id="searchB">查詢</button>
				<button id="resetB">清空</button>
			</div>
		</div>		
		<div class="toolbar">
			<button id="addB">增加</button>
			<button id="editB">修改</button>
			<button id="deleteB">刪除</button>
		</div>
		<table id="pageViewTable"></table>
	</div>
	<div id="pageViewAddOrEditForm">
		<div class="formarea">
			<form id="pageViewForm" type="ajax">

				<input type="hidden" id="id" name="id"/>
				<table>
					<tr>
						<td style="width:70px;" align="right" ><label for="requestIp">使用者IP:</label></td>
						<td>
							<div class="input">
								<input type="text" id="requestIp" name="requestIp"  class="validate[maxSize[50] ] "  size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="session">記錄會話ID:</label></td>
						<td>
							<div class="input">
								<input type="text" id="session" name="session"  class="validate[maxSize[100] ] "  size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="module">訪問的模組:</label></td>
						<td>
							<div class="input">
								<input type="text" id="module" name="module"  class="validate[maxSize[100] ] "  size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="visitTime">訪問時間:</label></td>
						<td>
							<div class="input">
								<input type="text" id="visitTime" name="visitTime"  class="Wdate " onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="40" />
							</div>
						</td>
					</tr>
					<tr>
						<td style="width:70px;" align="right" ><label for="visitCount">訪問數量:</label></td>
						<td>
							<div class="input">
								<input type="text" id="visitCount" name="visitCount"  class="validate[maxSize[10] ] "  size="40" />
							</div>
						</td>
					</tr>
				</table>

			</form>
		</div>
	</div>
</body>
</html>

 

 

pageView.js:

$(function() {
	jQuery("#pageViewTable").initGrid({
		url : templateRoot+"/jsp/moduleWeb/pageView/pageView_pagelist.do",
		height:	480,
//colNames:[ "id" ,  "使用者IP" ,  "記錄會話ID" ,  "訪問的模組" ,  "訪問時間" ,  "訪問數量"  ],	//如果colNames存在 則忽略colModel內的colName.
		colModel : [
{ colName : "id",		name : "id",		hidden : true,	id : true,	key:true,	index : "id",		width : 120,		align:"cente" } ,
{ colName : "使用者IP",	name : "requestIp",	hidden : false,	id : false,	key:false,	index : "request_ip",width : 120,		align:"cente" } ,
{ colName : "記錄會話ID",name : "session",	hidden : false,	id : false,	key:false,	index : "session",	width : 120,		align:"cente" } ,
{ colName : "訪問的模組",name : "module",	hidden : false,	id : false,	key:false,	index : "module",	width : 120,		align:"cente" } ,
{ colName : "訪問時間",	name : "visitTime",	hidden : false,	id : false,	key:false,	index : "visit_time",	width : 120,	align:"cente" } ,
{ colName : "訪問數量",	name : "visitCount",hidden : false,	id : false,	key:false,	index : "visit_count",	width : 120,	align:"cente" } 
		]
	});
	
	$("#pageViewAddOrEditForm").initDialog({
		width : 580,
		height: 220,
		buttons : { // 為對話方塊新增按鈕
			"儲存" : function() {
				pageViewSave();
			},
			"取消" : function() {
				$("#pageViewAddOrEditForm").dialog("close");
			}
		}
	});
	
	$("#addB").click(function() {
		addDialog();
	});
	$("#editB").click(function() {
		updateDialog();
	});
	$("#deleteB").click(function() {
		deleteByids();
	});
	$("#searchB").click(function() {
		search();
	});
	$("#resetB").click(function() {
		$("#pageViewSearchForm").clearForm();
	});

    function addDialog() {
		$("#pageViewForm").clearForm();
		$("#pageViewAddOrEditForm")
			.dialog("option", "title", "新增記錄網路訪問量視窗")
			.dialog("open");
	}
	
	function updateDialog() {
		var pageViewGrid = $("#pageViewTable"); 
		if (!pageViewGrid.ifGridSelectedOne()) {
			alert("請選擇一條記錄!");
			return false;
		}
		$("#pageViewForm").clearForm();
		$("#pageViewAddOrEditForm")
			.dialog("option", "title", "修改記錄網路訪問量視窗")
			.dialog("open");
//		var rowData = pageViewGrid.getSelectedRows()[0];
//		$("#pageViewForm").loadValues(rowData);
	 	var ids = pageViewGrid.getSelectedIds();
		$("#pageViewForm").loadForm(templateRoot + "/jsp/moduleWeb/pageView/pageView_load.do",{id : ids[0]});
	}

	function deleteByids() {
		var pageViewGrid = $("#pageViewTable");
		if(!pageViewGrid.ifGridSelected()){
			alert('請選擇要刪除的記錄!');
			return false;
		}
		var ids = pageViewGrid.getSelectedIds();
		if(confirm("確定要刪除 "+ ids.length+" 條資料嗎?")){
		 	var ids = pageViewGrid.getSelectedIds();
			$.ajax({
				url : templateRoot + "/jsp/moduleWeb/pageView/pageView_delete.do",
				data : {"ids" : ids},
				type : "post",	dataType : "json",	cache : false,	traditional :true,
				success : function(responseText, statusText, xhr, $form) {
					alert(responseText.message || "儲存成功!");
			    	if(responseText.success){
						$("#pageViewTable").reloadGrid();
						$("#gridDialog").dialog("close");
			    	}
			    }
			});
		 };
	}

	function pageViewSave() {
		$("#pageViewForm").submitForm({
			url : templateRoot + "/jsp/moduleWeb/pageView/pageView_save.do",
			success:function(responseText, statusText, xhr, $form){
				alert(responseText.message || "儲存成功!");
				if(responseText.success){
					$("#pageViewTable").reloadGrid();
					$("#pageViewAddOrEditForm").dialog("close");
				}
			},
			failure:function(data, options){
				alert(responseText.message || "儲存失敗!");
			}
		});
	}

	function search(){
		var params = $("#pageViewSearchForm").formToObject();
		$("#pageViewTable").searchGrid(params);  
	}

	function searchByParam(params){
	    $("#pageViewTable").searchGrid(params);  
	}
});

 

  • Java程式碼

 

action:PageViewAction.java

package com.liupengyuan.test.modulePage.pageView.action;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.liupengyuan.framework.util.JSONOuter;
import com.liupengyuan.framework.web.query.IGenericPage;
import com.liupengyuan.framework.web.struts2.BaseAction;
import com.liupengyuan.test.modulePage.pageView.model.PageView;
import com.liupengyuan.test.modulePage.pageView.service.PageViewService;

/**
 * @ClassName PageViewAction
 * @Description 記錄網路訪問量Action
 * @struts2配置檔名 struts-test-modulePage-pageView.xml
 * @spring3配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
 
@SuppressWarnings("serial")
@Controller("pageViewAction")
@Scope("prototype")
public class PageViewAction extends BaseAction<PageView> {
	@Autowired
	private PageViewService pageViewService;

	private PageView pageView;

	private String[] ids;

	/**
	 * 新增或者修改記錄
	 */
	public void save() {
		pageViewService.saveOrUpdate(pageView);
		JSONOuter.writeBeanMsg(getPrintWriter(), pageView,"資料儲存成功");
	}

	/**
	 * 載入資料物件
	 */
	public void load() {
		PageView pageViewObj = pageViewService.getById( pageView.getId()  );
		JSONOuter.writeBeanMsg(getPrintWriter(), pageViewObj);
	}

	/**
	 * 分頁查詢
	 */
	public void pagelist() {
		IGenericPage<PageView> iPage = pageViewService.findPageBy(
				pageView,
				this.getPage(),
				this.getRows(),
				this.getSidx(),
				this.getSord());
		JSONOuter.writePage(getPrintWriter(), iPage);
	}

	/**
	 * 資料列表
	 */
	public void list() {
		List<PageView> list = pageViewService.findListBy(
				pageView, this.getSidx(), this.getSord());
		JSONOuter.writeList(getPrintWriter(), list);
	}

	/**
	 * 批量刪除記錄
	 */
	public void delete() {
	String msg = "";
		if(ids!=null && ids.length>0){
			int s = pageViewService.deleteByIds(ids);
			msg = "成功刪除 " + s + " 條記錄!!!";
		}else{
			msg = "刪除失敗,請選擇要刪除的記錄!!!";
		}
		JSONOuter.writeSuccessMsg(getPrintWriter(), msg);
	}

	/**
	 * 模型驅動,自動裝配頁面屬性
	 */
	public PageView getModel() {
		pageView = new PageView();
		return pageView;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}
}
java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.liupengyuan.framework.util.JSONOuter;
import com.liupengyuan.framework.web.query.IGenericPage;
import com.liupengyuan.framework.web.struts2.BaseAction;
import com.liupengyuan.test.modulePage.pageView.model.PageView;
import com.liupengyuan.test.modulePage.pageView.service.PageViewService;

/**
 * @ClassName PageViewAction
 * @Description 記錄網路訪問量Action
 * @struts2配置檔名 struts-test-modulePage-pageView.xml
 * @spring3配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
 
@SuppressWarnings("serial")
@Controller("pageViewAction")
@Scope("prototype")
public class PageViewAction extends BaseAction<PageView> {
	@Autowired
	private PageViewService pageViewService;

	private PageView pageView;

	private String[] ids;

	/**
	 * 新增或者修改記錄
	 */
	public void save() {
		pageViewService.saveOrUpdate(pageView);
		JSONOuter.writeBeanMsg(getPrintWriter(), pageView,"資料儲存成功");
	}

	/**
	 * 載入資料物件
	 */
	public void load() {
		PageView pageViewObj = pageViewService.getById( pageView.getId()  );
		JSONOuter.writeBeanMsg(getPrintWriter(), pageViewObj);
	}

	/**
	 * 分頁查詢
	 */
	public void pagelist() {
		IGenericPage<PageView> iPage = pageViewService.findPageBy(
				pageView,
				this.getPage(),
				this.getRows(),
				this.getSidx(),
				this.getSord());
		JSONOuter.writePage(getPrintWriter(), iPage);
	}

	/**
	 * 資料列表
	 */
	public void list() {
		List<PageView> list = pageViewService.findListBy(
				pageView, this.getSidx(), this.getSord());
		JSONOuter.writeList(getPrintWriter(), list);
	}

	/**
	 * 批量刪除記錄
	 */
	public void delete() {
	String msg = "";
		if(ids!=null && ids.length>0){
			int s = pageViewService.deleteByIds(ids);
			msg = "成功刪除 " + s + " 條記錄!!!";
		}else{
			msg = "刪除失敗,請選擇要刪除的記錄!!!";
		}
		JSONOuter.writeSuccessMsg(getPrintWriter(), msg);
	}

	/**
	 * 模型驅動,自動裝配頁面屬性
	 */
	public PageView getModel() {
		pageView = new PageView();
		return pageView;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}
}

 

 

 

service介面:PageViewService.java

package com.liupengyuan.test.modulePage.pageView.service;

import java.util.List;

import com.liupengyuan.test.modulePage.pageView.model.PageView;
import com.liupengyuan.framework.web.query.IGenericPage;

/**
 * @ClassName PageViewService
 * @Description 記錄網路訪問量服務介面
 * @struts2 配置檔名 struts-test-modulePage-pageView.xml
 * @spring3 配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3 配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
public interface PageViewService {
	/**
	 * 根據通過主鍵ID獲取一個記錄網路訪問量例項
	 * @param id 記錄網路訪問量ID
	 * @return 記錄網路訪問量例項
	 */
	 
	public PageView getById(java.io.Serializable id);

	/**
	 * 批量刪除
	 * @param ids 要刪除的記錄網路訪問量ID集合
	 * @return 刪除成功的記錄生活
	 */
	public Integer deleteByIds(java.io.Serializable[] ids);
	public Integer deleteById(java.io.Serializable ids);

	/**
	 * 保持一個新增的記錄網路訪問量例項
	 * @param pageView 記錄網路訪問量
	 */
	public void save(PageView pageView);

	/**
	 * 儲存一個修改的記錄網路訪問量例項
	 * @param pageView 記錄網路訪問量
	 */
	public void update(PageView pageView);

	/**
	 * 儲存一個新增或修改的記錄網路訪問量例項
	 * @param pageView 記錄網路訪問量
	 */
	public void saveOrUpdate(PageView pageView);

	/**
	 * 分頁查詢
	 * @param param 查詢引數
	 * @param currentPage 當前頁碼
	 * @param rows 每頁記錄行數
	 * @param sort 排序欄位
	 * @param dir 排序方式、降序(desc)或升序(asc)
	 * @return 記錄網路訪問量例項集合
	 */
	public IGenericPage<PageView> findPageBy(
			PageView param,
			int currentPage,
			int rows,
			String sort,
			String dir);

	/**
	 * 主要是配合分頁查詢返回總記錄數
	 * @param param 主要查詢引數封裝在param中
	 * @return 記錄數
	 */
	public Integer getCountByParam(PageView param);

	/**
	 * 不分頁查詢
	 * @param param 主要查詢引數封裝在param中
	 * @param sort 排序欄位
	 * @param dir 排序方式、降序(desc)或升序(asc)
	 * @return 記錄網路訪問量例項集合
	 */
	public List<PageView> findListBy(PageView param, String sort, String dir);

}
java.util.List;

import com.liupengyuan.test.modulePage.pageView.model.PageView;
import com.liupengyuan.framework.web.query.IGenericPage;

/**
 * @ClassName PageViewService
 * @Description 記錄網路訪問量服務介面
 * @struts2 配置檔名 struts-test-modulePage-pageView.xml
 * @spring3 配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3 配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
public interface PageViewService {
	/**
	 * 根據通過主鍵ID獲取一個記錄網路訪問量例項
	 * @param id 記錄網路訪問量ID
	 * @return 記錄網路訪問量例項
	 */
	 
	public PageView getById(java.io.Serializable id);

	/**
	 * 批量刪除
	 * @param ids 要刪除的記錄網路訪問量ID集合
	 * @return 刪除成功的記錄生活
	 */
	public Integer deleteByIds(java.io.Serializable[] ids);
	public Integer deleteById(java.io.Serializable ids);

	/**
	 * 保持一個新增的記錄網路訪問量例項
	 * @param pageView 記錄網路訪問量
	 */
	public void save(PageView pageView);

	/**
	 * 儲存一個修改的記錄網路訪問量例項
	 * @param pageView 記錄網路訪問量
	 */
	public void update(PageView pageView);

	/**
	 * 儲存一個新增或修改的記錄網路訪問量例項
	 * @param pageView 記錄網路訪問量
	 */
	public void saveOrUpdate(PageView pageView);

	/**
	 * 分頁查詢
	 * @param param 查詢引數
	 * @param currentPage 當前頁碼
	 * @param rows 每頁記錄行數
	 * @param sort 排序欄位
	 * @param dir 排序方式、降序(desc)或升序(asc)
	 * @return 記錄網路訪問量例項集合
	 */
	public IGenericPage<PageView> findPageBy(
			PageView param,
			int currentPage,
			int rows,
			String sort,
			String dir);

	/**
	 * 主要是配合分頁查詢返回總記錄數
	 * @param param 主要查詢引數封裝在param中
	 * @return 記錄數
	 */
	public Integer getCountByParam(PageView param);

	/**
	 * 不分頁查詢
	 * @param param 主要查詢引數封裝在param中
	 * @param sort 排序欄位
	 * @param dir 排序方式、降序(desc)或升序(asc)
	 * @return 記錄網路訪問量例項集合
	 */
	public List<PageView> findListBy(PageView param, String sort, String dir);

}

 

 

 

service實現類:PageViewServiceImpl.java

package com.liupengyuan.test.modulePage.pageView.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liupengyuan.framework.web.query.IGenericPage;

import com.liupengyuan.test.modulePage.pageView.dao.PageViewDao;
import com.liupengyuan.test.modulePage.pageView.model.PageView;
import com.liupengyuan.test.modulePage.pageView.service.PageViewService;


/**
 * @ClassName PageViewServiceImpl
 * @Description 記錄網路訪問量服務實現類
 * @struts2 配置檔名 struts-test-modulePage-pageView.xml
 * @spring3 配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3 配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
 
@Service("pageViewService")
public class PageViewServiceImpl implements PageViewService {
	@Autowired
	private PageViewDao pageViewDao;

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#getById(java.io.Serializable)
	 */
	public PageView getById(java.io.Serializable id) {
		return pageViewDao.getById(id);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#deleteByIds(java.io.Serializable[])
	 */
	public Integer deleteByIds(java.io.Serializable[] ids) {
		return pageViewDao.deleteByIds(ids);

	}
	
	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#deleteById(java.io.Serializable)
	 */
	public Integer deleteById(java.io.Serializable id) {
		return pageViewDao.deleteById(id);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#save(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public void save(PageView ob) {
		pageViewDao.save(ob);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#update(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public void update(PageView ob) {
		pageViewDao.update(ob);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#saveOrUpdate(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public void saveOrUpdate(PageView ob) {
		if (ob != null) {
			// 如果ID不為空說明是修改的例項,為更新操作
			if (null != ob.getId() && StringUtils.isNotEmpty(String.valueOf(ob.getId()))) {
				pageViewDao.update(ob);
			} else {
				pageViewDao.save(ob);
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#findPageBy(com.liupengyuan.test.modulePage.pageView.model.PageView, int, int, java.lang.String, java.lang.String)
	 */
	public IGenericPage<PageView> findPageBy(
			PageView param,
			int currentPage,
			int rows,
			String sort,
			String dir) {
		return pageViewDao.findPageBy(
				wrapParams(param), currentPage, rows, sort, dir);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#getCountByParam(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public Integer getCountByParam(PageView param) {
		return pageViewDao.getCountBy(wrapParams(param));
	}

	/**
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#findListBy(com.liupengyuan.test.modulePage.pageView.PageView, java.lang.String, java.lang.String)
	 */
	public List<PageView> findListBy(
			PageView param,
			String sort,
			String dir) {
		return pageViewDao.findListBy(
				wrapParams(param), sort, dir);
	}

	/**
	 * 為模糊查詢前後加裝%%
	 */
	private PageView wrapParams(PageView param) {
		if(param != null){
			if(StringUtils.isNotEmpty(param.getRequestIp())){
				param.setRequestIp("%"+param.getRequestIp()+"%");
			}
			if(StringUtils.isNotEmpty(param.getSession())){
				param.setSession("%"+param.getSession()+"%");
			}
			if(StringUtils.isNotEmpty(param.getModule())){
				param.setModule("%"+param.getModule()+"%");
			}
		}
		return param;
	}
}
java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liupengyuan.framework.web.query.IGenericPage;

import com.liupengyuan.test.modulePage.pageView.dao.PageViewDao;
import com.liupengyuan.test.modulePage.pageView.model.PageView;
import com.liupengyuan.test.modulePage.pageView.service.PageViewService;


/**
 * @ClassName PageViewServiceImpl
 * @Description 記錄網路訪問量服務實現類
 * @struts2 配置檔名 struts-test-modulePage-pageView.xml
 * @spring3 配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3 配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
 
@Service("pageViewService")
public class PageViewServiceImpl implements PageViewService {
	@Autowired
	private PageViewDao pageViewDao;

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#getById(java.io.Serializable)
	 */
	public PageView getById(java.io.Serializable id) {
		return pageViewDao.getById(id);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#deleteByIds(java.io.Serializable[])
	 */
	public Integer deleteByIds(java.io.Serializable[] ids) {
		return pageViewDao.deleteByIds(ids);

	}
	
	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#deleteById(java.io.Serializable)
	 */
	public Integer deleteById(java.io.Serializable id) {
		return pageViewDao.deleteById(id);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#save(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public void save(PageView ob) {
		pageViewDao.save(ob);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#update(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public void update(PageView ob) {
		pageViewDao.update(ob);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#saveOrUpdate(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public void saveOrUpdate(PageView ob) {
		if (ob != null) {
			// 如果ID不為空說明是修改的例項,為更新操作
			if (null != ob.getId() && StringUtils.isNotEmpty(String.valueOf(ob.getId()))) {
				pageViewDao.update(ob);
			} else {
				pageViewDao.save(ob);
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#findPageBy(com.liupengyuan.test.modulePage.pageView.model.PageView, int, int, java.lang.String, java.lang.String)
	 */
	public IGenericPage<PageView> findPageBy(
			PageView param,
			int currentPage,
			int rows,
			String sort,
			String dir) {
		return pageViewDao.findPageBy(
				wrapParams(param), currentPage, rows, sort, dir);
	}

	/*
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#getCountByParam(com.liupengyuan.test.modulePage.pageView.model.PageView)
	 */
	public Integer getCountByParam(PageView param) {
		return pageViewDao.getCountBy(wrapParams(param));
	}

	/**
	 * (non-Javadoc)
	 * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#findListBy(com.liupengyuan.test.modulePage.pageView.PageView, java.lang.String, java.lang.String)
	 */
	public List<PageView> findListBy(
			PageView param,
			String sort,
			String dir) {
		return pageViewDao.findListBy(
				wrapParams(param), sort, dir);
	}

	/**
	 * 為模糊查詢前後加裝%%
	 */
	private PageView wrapParams(PageView param) {
		if(param != null){
			if(StringUtils.isNotEmpty(param.getRequestIp())){
				param.setRequestIp("%"+param.getRequestIp()+"%");
			}
			if(StringUtils.isNotEmpty(param.getSession())){
				param.setSession("%"+param.getSession()+"%");
			}
			if(StringUtils.isNotEmpty(param.getModule())){
				param.setModule("%"+param.getModule()+"%");
			}
		}
		return param;
	}
}


DAO介面:PageViewDao.java

package com.liupengyuan.test.modulePage.pageView.dao;

import com.liupengyuan.framework.dao.IBaseGenericDAO;
import com.liupengyuan.test.modulePage.pageView.model.PageView;

/**
 * @ClassName PageViewDao
 * @Description 記錄網路訪問量DAO介面
 * @struts2 配置檔名 struts-test-modulePage-pageView.xml
 * @spring3 配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3 配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
public interface PageViewDao extends IBaseGenericDAO<PageView> {

}

 

 

 

DAO實現類:PageViewDaoImpl.java

package com.liupengyuan.test.modulePage.pageView.dao.impl;

import org.springframework.stereotype.Repository;
import com.liupengyuan.framework.dao.MybatisBaseGenericDAOImpl;
import com.liupengyuan.framework.util.GeneratorKey;
import com.liupengyuan.test.modulePage.pageView.dao.PageViewDao;
import com.liupengyuan.test.modulePage.pageView.model.PageView;


/**
 * @ClassName PageViewDaoImpl
 * @Description 記錄網路訪問量DAO實現類 
 * @struts2 配置檔名 struts-test-modulePage-pageView.xml
 * @spring3 配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3 配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
@Repository("pageViewDao")
public class PageViewDaoImpl
extends MybatisBaseGenericDAOImpl<PageView>
implements PageViewDao {
	/**
	 * 生成UUID主鍵值。
	 * @param ob 記錄網路訪問量
	 */
	public void generateId(PageView ob) {
		//id
		if(null == ob.getId() || ob.getId().length() == 0){
			ob.setId(GeneratorKey.genaraId());
		}
	}
}

 

 

 

model:PageView.java

package com.liupengyuan.test.modulePage.pageView.model;

/**
 * @ClassName PageView
 * @Description 記錄網路訪問量 實體(領域)物件
 * @struts2 配置檔名 struts-test-modulePage-pageView.xml
 * @spring3 配置檔名 spring-test-modulePage-pageView.xml
 * @mybatis3 配置檔名 mybatis-test-modulePage-pageView.xml
 * @表名 sys_page_view
 * @author generate
 * @date - 2015-02-10 15:33:10
 * @version V1.0 
 */
public class PageView implements java.io.Serializable {

	/** id */
	private java.lang.String id;

	/**
	 * 獲取id
	 * @return id
	 */
	public java.lang.String getId() {
		return this.id;
	}
	/**
	 * 設定id
	 */
	public void setId(java.lang.String id){
		this.id = id;
	}
	
	/** 使用者IP */
	private java.lang.String requestIp;

	/**
	 * 獲取使用者IP
	 * @return 使用者IP
	 */
	public java.lang.String getRequestIp() {
		return this.requestIp;
	}
	/**
	 * 設定使用者IP
	 */
	public void setRequestIp(java.lang.String requestIp){
		this.requestIp = requestIp;
	}
	
	/** 記錄會話ID */
	private java.lang.String session;

	/**
	 * 獲取記錄會話ID
	 * @return 記錄會話ID
	 */
	public java.lang.String getSession() {
		return this.session;
	}
	/**
	 * 設定記錄會話ID
	 */
	public void setSession(java.lang.String session){
		this.session = session;
	}
	
	/** 訪問的模組 */
	private java.lang.String module;

	/**
	 * 獲取訪問的模組
	 * @return 訪問的模組
	 */
	public java.lang.String getModule() {
		return this.module;
	}
	/**
	 * 設定訪問的模組
	 */
	public void setModule(java.lang.String module){
		this.module = module;
	}
	
	/** 訪問時間 */
	private java.util.Date visitTime;

	/**
	 * 獲取訪問時間
	 * @return 訪問時間
	 */
	public java.util.Date getVisitTime() {
		return this.visitTime;
	}
	/**
	 * 設定訪問時間
	 */
	public void setVisitTime(java.util.Date visitTime){
		this.visitTime = visitTime;
	}
	
	/** 訪問數量 */
	private java.lang.Integer visitCount;

	/**
	 * 獲取訪問數量
	 * @return 訪問數量
	 */
	public java.lang.Integer getVisitCount() {
		return this.visitCount;
	}
	/**
	 * 設定訪問數量
	 */
	public void setVisitCount(java.lang.Integer visitCount){
		this.visitCount = visitCount;
	}
}
java.io.Serializable {

	/** id */
	private java.lang.String id;

	/**
	 * 獲取id
	 * @return id
	 */
	public java.lang.String getId() {
		return this.id;
	}
	/**
	 * 設定id
	 */
	public void setId(java.lang.String id){
		this.id = id;
	}
	
	/** 使用者IP */
	private java.lang.String requestIp;

	/**
	 * 獲取使用者IP
	 * @return 使用者IP
	 */
	public java.lang.String getRequestIp() {
		return this.requestIp;
	}
	/**
	 * 設定使用者IP
	 */
	public void setRequestIp(java.lang.String requestIp){
		this.requestIp = requestIp;
	}
	
	/** 記錄會話ID */
	private java.lang.String session;

	/**
	 * 獲取記錄會話ID
	 * @return 記錄會話ID
	 */
	public java.lang.String getSession() {
		return this.session;
	}
	/**
	 * 設定記錄會話ID
	 */
	public void setSession(java.lang.String session){
		this.session = session;
	}
	
	/** 訪問的模組 */
	private java.lang.String module;

	/**
	 * 獲取訪問的模組
	 * @return 訪問的模組
	 */
	public java.lang.String getModule() {
		return this.module;
	}
	/**
	 * 設定訪問的模組
	 */
	public void setModule(java.lang.String module){
		this.module = module;
	}
	
	/** 訪問時間 */
	private java.util.Date visitTime;

	/**
	 * 獲取訪問時間
	 * @return 訪問時間
	 */
	public java.util.Date getVisitTime() {
		return this.visitTime;
	}
	/**
	 * 設定訪問時間
	 */
	public void setVisitTime(java.util.Date visitTime){
		this.visitTime = visitTime;
	}
	
	/** 訪問數量 */
	private java.lang.Integer visitCount;

	/**
	 * 獲取訪問數量
	 * @return 訪問數量
	 */
	public java.lang.Integer getVisitCount() {
		return this.visitCount;
	}
	/**
	 * 設定訪問數量
	 */
	public void setVisitCount(java.lang.Integer visitCount){
		this.visitCount = visitCount;
	}
}

 

 

 

  • XML 配置檔案

 

mybatis檔案:mybatis-test-modulePage-pageView.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.liupengyuan.test.modulePage.pageView.model.PageView">
	<resultMap id="pageViewResultMap" type="com.liupengyuan.test.modulePage.pageView.model.PageView">
		<!-- id -->
		<result column="id" property="id" jdbcType="VARCHAR" />
		<!-- 使用者IP -->
		<result column="request_ip" property="requestIp" jdbcType="VARCHAR" />
		<!-- 記錄會話ID -->
		<result column="session" property="session" jdbcType="VARCHAR" />
		<!-- 訪問的模組 -->
		<result column="module" property="module" jdbcType="VARCHAR" />
		<!-- 訪問時間 -->
		<result column="visit_time" property="visitTime" jdbcType="TIMESTAMP" />
		<!-- 訪問數量 -->
		<result column="visit_count" property="visitCount" jdbcType="INTEGER" />
	</resultMap>
	<!-- 表名 -->
	<sql id="tableNameSql">
		sys_page_view 
	</sql>

	<!-- 用於select查詢、insert的公用抽取的列 -->
	<sql id="commonSelectColumnsPrefix">
        	id ,
        	request_ip ,
        	session ,
        	module ,
        	visit_time ,
        	visit_count 
	</sql>

	<!-- 按主鍵查詢條件語句 -->
	<sql id="conditionOnlyId">
		id = #{id} 
	</sql>
	
	<sql id="mainSql">
		SELECT
			<include refid="commonSelectColumnsPrefix"/>
		FROM
			<include refid="tableNameSql"/> p
	</sql>

	<sql id="varSql">
		<where>
			<if test="requestIp!=null and requestIp!=''">and p.request_ip like #{requestIp} </if>
			<if test="session!=null and session!=''">and p.session like #{session} </if>
			<if test="module!=null and module!=''">and p.module like #{module} </if>
		</where>
	</sql>

	<select id="findPageBy" parameterType="java.util.Map" resultMap="pageViewResultMap">
 		<include refid="mainSql"/>
 		<include refid="varSql"/>
		<if test="SORT != null and SORT != ''">
 			order by ${SORT}
 			<if test="DIR != null and DIR != ''">
 				 ${DIR}
 			</if>
 		</if>
	</select>

	<select id="getById" parameterType="String" resultMap="pageViewResultMap">
		<include refid="mainSql"/>
		where <include refid="conditionOnlyId"/>
	</select>

	<select id="getCountBy" parameterType="java.util.Map" resultType="INTEGER">
		SELECT
			COUNT(*) AS C
		FROM
			<include refid="tableNameSql"/> p
		<include refid="varSql"/>
	</select>

	<select id="findListBy" parameterType="java.util.Map" resultMap="pageViewResultMap">
		<include refid="mainSql"/>
		<include refid="varSql"/>
		<if test="SORT != null and SORT != ''">
 			order by ${SORT}
 			<if test="DIR != null and DIR != ''">
 				 ${DIR}
 			</if>
 		</if>
	</select>

	<insert id="save" parameterType="com.liupengyuan.test.modulePage.pageView.model.PageView">
		insert into
			<include refid="tableNameSql"/>
		(
			<include refid="commonSelectColumnsPrefix"/>
		)
		values
		(
			#{id, jdbcType=VARCHAR} ,
			#{requestIp, jdbcType=VARCHAR} ,
			#{session, jdbcType=VARCHAR} ,
			#{module, jdbcType=VARCHAR} ,
			#{visitTime, jdbcType=TIMESTAMP} ,
			#{visitCount, jdbcType=INTEGER} 
		)
	</insert>
	<update id="update" parameterType="com.liupengyuan.test.modulePage.pageView.model.PageView">
		update
			<include refid="tableNameSql"/>
		set
			request_ip = #{requestIp, jdbcType=VARCHAR} ,
			session = #{session, jdbcType=VARCHAR} ,
			module = #{module, jdbcType=VARCHAR} ,
			visit_time = #{visitTime, jdbcType=TIMESTAMP} ,
			visit_count = #{visitCount, jdbcType=INTEGER} 
		where <include refid="conditionOnlyId"/>
	</update>

	<delete id="deleteByIds" parameterType="Object[]">
		delete from <include refid="tableNameSql"/> 
		where id in <foreach index="index" item="item" collection="array" separator="," open="(" close=")" >#{item}</foreach>
	</delete>

	<delete id="deleteById" parameterType="Object">
		delete from <include refid="tableNameSql"/> where <include refid="conditionOnlyId"/>
	</delete>

</mapper>java.util.Map" resultMap="pageViewResultMap">
 		<include refid="mainSql"/>
 		<include refid="varSql"/>
		<if test="SORT != null and SORT != ''">
 			order by ${SORT}
 			<if test="DIR != null and DIR != ''">
 				 ${DIR}
 			</if>
 		</if>
	</select>

	<select id="getById" parameterType="String" resultMap="pageViewResultMap">
		<include refid="mainSql"/>
		where <include refid="conditionOnlyId"/>
	</select>

	<select id="getCountBy" parameterType="java.util.Map" resultType="INTEGER">
		SELECT
			COUNT(*) AS C
		FROM
			<include refid="tableNameSql"/> p
		<include refid="varSql"/>
	</select>

	<select id="findListBy" parameterType="java.util.Map" resultMap="pageViewResultMap">
		<include refid="mainSql"/>
		<include refid="varSql"/>
		<if test="SORT != null and SORT != ''">
 			order by ${SORT}
 			<if test="DIR != null and DIR != ''">
 				 ${DIR}
 			</if>
 		</if>
	</select>

	<insert id="save" parameterType="com.liupengyuan.test.modulePage.pageView.model.PageView">
		insert into
			<include refid="tableNameSql"/>
		(
			<include refid="commonSelectColumnsPrefix"/>
		)
		values
		(
			#{id, jdbcType=VARCHAR} ,
			#{requestIp, jdbcType=VARCHAR} ,
			#{session, jdbcType=VARCHAR} ,
			#{module, jdbcType=VARCHAR} ,
			#{visitTime, jdbcType=TIMESTAMP} ,
			#{visitCount, jdbcType=INTEGER} 
		)
	</insert>
	<update id="update" parameterType="com.liupengyuan.test.modulePage.pageView.model.PageView">
		update
			<include refid="tableNameSql"/>
		set
			request_ip = #{requestIp, jdbcType=VARCHAR} ,
			session = #{session, jdbcType=VARCHAR} ,
			module = #{module, jdbcType=VARCHAR} ,
			visit_time = #{visitTime, jdbcType=TIMESTAMP} ,
			visit_count = #{visitCount, jdbcType=INTEGER} 
		where <include refid="conditionOnlyId"/>
	</update>

	<delete id="deleteByIds" parameterType="Object[]">
		delete from <include refid="tableNameSql"/> 
		where id in <foreach index="index" item="item" collection="array" separator="," open="(" close=")" >#{item}</foreach>
	</delete>

	<delete id="deleteById" parameterType="Object">
		delete from <include refid="tableNameSql"/> where <include refid="conditionOnlyId"/>
	</delete>

</mapper>

 

 

 

spring配置檔案:spring-test-modulePage-pageView.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
	<context:component-scan base-package="com.liupengyuan.test.modulePage.pageView.*" />
</beans>


Struts2配置檔案:struts-test-modulePage-pageView.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="com.liupengyuan.test.modulePage.pageView.action.PageViewAction" extends="struts-default" namespace="/jsp/moduleWeb/pageView">

		<action name="pageView_*"
				class="pageViewAction"
				method="{1}">
		</action>
		<action name="pageView">
			<result>/jsp/moduleWeb/pageView/pageView.jsp</result>
		</action>

	</package>
</struts>

 

 

 

 

 

 

 

結束...