整合框架 javaweb开发平台ssmy_m(与代码生成) java struts2 mybatis spring maven jquery



整合框架 javaweb开发平台ssmy_m(与代码生成) java struts2 mybatis spring maven jquery

项目设想,在项目开发中,我们的开发人员大多数时间都在重复开发 同样的关键字,同样的语法. 但就在这样的情况下还会经常发生语法的错误,而且每个开发人员的代码风格不同. 其他人员阅读困难.新人的学习成本也会增加.

这些问题会浪费很多时间,也会影响到开发人员的心情,和程序质量. 由这些问题我想的解决方法是 <代码生成工具> . 代码生成可以解决上述问题,加强约定. 对于普通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主页  http://liupengyuan.xicp.cn
 ssmy开发框架SSMy  http://liupengyuan.xicp.cn/ssmy_m/
 ssmy框架的代码生成工具  http://liupengyuan.xicp.cn/generate_m/
 generate_m生成的代码示例  http://download.csdn.net/detail/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 项目里

[html] view plain copy

在CODE上查看代码片派生到我的代码片

  1. <?xml version=”1.0″ encoding=”UTF-8″?>
  2. <!– 用于生成数据库的配置文件 –>
  3. <dbConfigs>
  4.     <dbConfig id=”localMysql”><!– 配置名称 –>
  5.         <url>jdbc:mysql://localhost:3306/ssmy</url><!– url –>
  6.         <username>root</username><!– </username> –>
  7.         <password>root</password><!– password –>
  8.         <driverClass>com.mysql.jdbc.Driver</driverClass><!– driverClass –>
  9.     </dbConfig>
  10.     <dbConfig id=”localOracle”>
  11.         <url>jdbc:oracle:thin:@localhost:1521:orcl</url>
  12.         <username>ssmy</username>
  13.         <password>ssmy</password>
  14.         <driverClass>oracle.jdbc.driver.OracleDriver</driverClass>
  15.     </dbConfig>
  16.     <dbConfig id=”dsd_zjk”>
  17.         <url>jdbc:oracle:thin:@192.168.3.34:1521:orcl</url>
  18.         <username>dsd_zjk</username>
  19.         <password>dsd_zjk</password>
  20.         <driverClass>oracle.jdbc.driver.OracleDriver</driverClass>
  21.     </dbConfig>
  22. </dbConfigs>

 

代码生成页面:右键新窗口打开图片可以放大

 

 

 

 

“项目基本WEB层命名空间”  和  “模块WEB层命名空间”   这两个input会决定Struts2的命名空间和JS的引用路径


 

[html] view plain copy

在CODE上查看代码片派生到我的代码片

  1. <struts>
  2.     <package name=”com.liupengyuan.framework.pageView.action.PageViewAction” extends=”struts-default” namespace=”/framework/pageView”>
  3.         <action name=”pageView_*”
  4.                 class=”pageViewAction”
  5.                 method=”{1}”>
  6.         </action>
  7.         <action name=”pageView”>
  8.             <result>/framework/pageView/pageView.jsp</result>
  9.         </action>
  10.     </package>
  11. </struts>

 

 

 

  • 代码目录:

 

 

 

  • Zip包目录:

 

 

 

  • HTML JS 代码
pageView.jsp:

[html] view plain copy

在CODE上查看代码片派生到我的代码片

  1. <%@ page language=”java” pageEncoding=”UTF-8″%>
  2. <!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Strict//EN” ”http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
  3. <html>
  4.   <head>
  5.     <title>记录网络访问量</title>
  6.     <%@ include file=”/common/include_com.jsp”%>
  7.     <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
  8.     <script src=”${pageContext.request.contextPath}/jsp/moduleWeb/pageView/js/pageView.js”></script>
  9.     <!–<script src=”js/pageView.js”></script>–>
  10.   </head>
  11. <body>
  12.     <div class=”ui-layout-north”>
  13.         <div class=”navbar”><font size=”2″ > 当前操作:记录网络访问量</font></div>
  14.     </div>
  15.     <div class=”ui-layout-center”>
  16. <!– <div class=”title_level1″>查询</div> –>
  17.         <div class=”formarea”>
  18.             <form id=”pageViewSearchForm”>
  19.             <fieldset>
  20.             <legend style=”margin-left: 10px;”>查询</legend>
  21.                 <table>
  22.                     <tr>
  23.                         <td style=”width:150px;” align=”right” ><label for=”requestIp”>用户IP:</label></td>
  24.                         <td>
  25.                             <div class=”input”>
  26.                                 <input type=”text” name=”requestIp”  size=”40″  />
  27.                             </div>
  28.                         </td>
  29.                         <td style=”width:150px;” align=”right” ><label for=”session”>记录会话ID:</label></td>
  30.                         <td>
  31.                             <div class=”input”>
  32.                                 <input type=”text” name=”session”  size=”40″  />
  33.                             </div>
  34.                         </td>
  35.                     </tr>
  36.                     <tr>
  37.                         <td style=”width:150px;” align=”right” ><label for=”module”>访问的模块:</label></td>
  38.                         <td>
  39.                             <div class=”input”>
  40.                                 <input type=”text” name=”module”  size=”40″  />
  41.                             </div>
  42.                         </td>
  43.                         <td style=”width:150px;” align=”right” ><label for=”visitTime”>访问时间:</label></td>
  44.                         <td>
  45.                             <div class=”input”>
  46.                                 <input type=”text” name=”visitTime” class=”Wdate” onClick=”WdatePicker({dateFmt:’yyyy-MM-dd HH:mm:ss’})” size=”40″  />
  47.                             </div>
  48.                         </td>
  49.                     </tr>
  50.                     <tr>
  51.                         <td style=”width:150px;” align=”right” ><label for=”visitCount”>访问数量:</label></td>
  52.                         <td>
  53.                             <div class=”input”>
  54.                                 <input type=”text” name=”visitCount”  size=”40″  />
  55.                             </div>
  56.                         </td>
  57.                     </tr>
  58.                 </table>
  59.             </fieldset>
  60.             </form>
  61.             <div class=”buttons”>
  62.                 <button id=”searchB”>查询</button>
  63.                 <button id=”resetB”>清空</button>
  64.             </div>
  65.         </div>
  66.         <div class=”toolbar”>
  67.             <button id=”addB”>增加</button>
  68.             <button id=”editB”>修改</button>
  69.             <button id=”deleteB”>删除</button>
  70.         </div>
  71.         <table id=”pageViewTable”></table>
  72.     </div>
  73.     <div id=”pageViewAddOrEditForm”>
  74.         <div class=”formarea”>
  75.             <form id=”pageViewForm” type=”ajax”>
  76.                 <input type=”hidden” id=”id” name=”id”/>
  77.                 <table>
  78.                     <tr>
  79.                         <td style=”width:70px;” align=”right” ><label for=”requestIp”>用户IP:</label></td>
  80.                         <td>
  81.                             <div class=”input”>
  82.                                 <input type=”text” id=”requestIp” name=”requestIp”  class=”validate[maxSize[50] ] ”  size=”40″ />
  83.                             </div>
  84.                         </td>
  85.                     </tr>
  86.                     <tr>
  87.                         <td style=”width:70px;” align=”right” ><label for=”session”>记录会话ID:</label></td>
  88.                         <td>
  89.                             <div class=”input”>
  90.                                 <input type=”text” id=”session” name=”session”  class=”validate[maxSize[100] ] ”  size=”40″ />
  91.                             </div>
  92.                         </td>
  93.                     </tr>
  94.                     <tr>
  95.                         <td style=”width:70px;” align=”right” ><label for=”module”>访问的模块:</label></td>
  96.                         <td>
  97.                             <div class=”input”>
  98.                                 <input type=”text” id=”module” name=”module”  class=”validate[maxSize[100] ] ”  size=”40″ />
  99.                             </div>
  100.                         </td>
  101.                     </tr>
  102.                     <tr>
  103.                         <td style=”width:70px;” align=”right” ><label for=”visitTime”>访问时间:</label></td>
  104.                         <td>
  105.                             <div class=”input”>
  106.                                 <input type=”text” id=”visitTime” name=”visitTime”  class=”Wdate ” onClick=”WdatePicker({dateFmt:’yyyy-MM-dd HH:mm:ss’})” size=”40″ />
  107.                             </div>
  108.                         </td>
  109.                     </tr>
  110.                     <tr>
  111.                         <td style=”width:70px;” align=”right” ><label for=”visitCount”>访问数量:</label></td>
  112.                         <td>
  113.                             <div class=”input”>
  114.                                 <input type=”text” id=”visitCount” name=”visitCount”  class=”validate[maxSize[10] ] ”  size=”40″ />
  115.                             </div>
  116.                         </td>
  117.                     </tr>
  118.                 </table>
  119.             </form>
  120.         </div>
  121.     </div>
  122. </body>
  123. </html>

pageView.js:

[javascript] view plain copy

在CODE上查看代码片派生到我的代码片

  1. $(function() {
  2.     jQuery(“#pageViewTable”).initGrid({
  3.         url : templateRoot+”/jsp/moduleWeb/pageView/pageView_pagelist.do”,
  4.         height: 480,
  5. //colNames:[ "id" ,  "用户IP" ,  "记录会话ID" ,  "访问的模块" ,  "访问时间" ,  "访问数量"  ],  //如果colNames存在 则忽略colModel内的colName.
  6.         colModel : [
  7. { colName : "id",       name : "id",        hidden : true,  id : true,  key:true,   index : "id",       width : 120,        align:"cente" } ,
  8. { colName : "用户IP", name : "requestIp", hidden : false, id : false, key:false,  index : "request_ip",width : 120,       align:"cente" } ,
  9. { colName : "记录会话ID",name : "session",  hidden : false, id : false, key:false,  index : "session",  width : 120,        align:"cente" } ,
  10. { colName : "访问的模块",name : "module",    hidden : false, id : false, key:false,  index : "module",   width : 120,        align:"cente" } ,
  11. { colName : "访问时间", name : "visitTime", hidden : false, id : false, key:false,  index : "visit_time",   width : 120,    align:"cente" } ,
  12. { colName : "访问数量", name : "visitCount",hidden : false, id : false, key:false,  index : "visit_count",  width : 120,    align:"cente" }
  13.         ]
  14.     });
  15.     $(“#pageViewAddOrEditForm”).initDialog({
  16.         width : 580,
  17.         height: 220,
  18.         buttons : { // 为对话框添加按钮
  19.             ”保存” : function() {
  20.                 pageViewSave();
  21.             },
  22.             ”取消” : function() {
  23.                 $(“#pageViewAddOrEditForm”).dialog(“close”);
  24.             }
  25.         }
  26.     });
  27.     $(“#addB”).click(function() {
  28.         addDialog();
  29.     });
  30.     $(“#editB”).click(function() {
  31.         updateDialog();
  32.     });
  33.     $(“#deleteB”).click(function() {
  34.         deleteByids();
  35.     });
  36.     $(“#searchB”).click(function() {
  37.         search();
  38.     });
  39.     $(“#resetB”).click(function() {
  40.         $(“#pageViewSearchForm”).clearForm();
  41.     });
  42.     function addDialog() {
  43.         $(“#pageViewForm”).clearForm();
  44.         $(“#pageViewAddOrEditForm”)
  45.             .dialog(“option”, ”title”, ”添加记录网络访问量窗口”)
  46.             .dialog(“open”);
  47.     }
  48.     function updateDialog() {
  49.         var pageViewGrid = $(“#pageViewTable”);
  50.         if (!pageViewGrid.ifGridSelectedOne()) {
  51.             alert(“请选择一条记录!”);
  52.             return false;
  53.         }
  54.         $(“#pageViewForm”).clearForm();
  55.         $(“#pageViewAddOrEditForm”)
  56.             .dialog(“option”, ”title”, ”修改记录网络访问量窗口”)
  57.             .dialog(“open”);
  58. //      var rowData = pageViewGrid.getSelectedRows()[0];
  59. //      $(“#pageViewForm”).loadValues(rowData);
  60.         var ids = pageViewGrid.getSelectedIds();
  61.         $(“#pageViewForm”).loadForm(templateRoot + ”/jsp/moduleWeb/pageView/pageView_load.do”,{id : ids[0]});
  62.     }
  63.     function deleteByids() {
  64.         var pageViewGrid = $(“#pageViewTable”);
  65.         if(!pageViewGrid.ifGridSelected()){
  66.             alert(‘请选择要删除的记录!’);
  67.             return false;
  68.         }
  69.         var ids = pageViewGrid.getSelectedIds();
  70.         if(confirm(“确定要删除 ”+ ids.length+” 条数据吗?”)){
  71.             var ids = pageViewGrid.getSelectedIds();
  72.             $.ajax({
  73.                 url : templateRoot + ”/jsp/moduleWeb/pageView/pageView_delete.do”,
  74.                 data : {“ids” : ids},
  75.                 type : ”post”,  dataType : ”json”,  cache : false,  traditional :true,
  76.                 success : function(responseText, statusText, xhr, $form) {
  77.                     alert(responseText.message || ”保存成功!”);
  78.                     if(responseText.success){
  79.                         $(“#pageViewTable”).reloadGrid();
  80.                         $(“#gridDialog”).dialog(“close”);
  81.                     }
  82.                 }
  83.             });
  84.          };
  85.     }
  86.     function pageViewSave() {
  87.         $(“#pageViewForm”).submitForm({
  88.             url : templateRoot + ”/jsp/moduleWeb/pageView/pageView_save.do”,
  89.             success:function(responseText, statusText, xhr, $form){
  90.                 alert(responseText.message || ”保存成功!”);
  91.                 if(responseText.success){
  92.                     $(“#pageViewTable”).reloadGrid();
  93.                     $(“#pageViewAddOrEditForm”).dialog(“close”);
  94.                 }
  95.             },
  96.             failure:function(data, options){
  97.                 alert(responseText.message || ”保存失败!”);
  98.             }
  99.         });
  100.     }
  101.     function search(){
  102.         var params = $(“#pageViewSearchForm”).formToObject();
  103.         $(“#pageViewTable”).searchGrid(params);
  104.     }
  105.     function searchByParam(params){
  106.         $(“#pageViewTable”).searchGrid(params);
  107.     }
  108. });
  • Java代码

 

action:PageViewAction.Java

[java] view plain copy

在CODE上查看代码片派生到我的代码片

  1. package com.liupengyuan.test.modulePage.pageView.action;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.context.annotation.Scope;
  5. import org.springframework.stereotype.Controller;
  6. import com.liupengyuan.framework.util.JSONOuter;
  7. import com.liupengyuan.framework.web.query.IGenericPage;
  8. import com.liupengyuan.framework.web.struts2.BaseAction;
  9. import com.liupengyuan.test.modulePage.pageView.model.PageView;
  10. import com.liupengyuan.test.modulePage.pageView.service.PageViewService;
  11. /**
  12.  * @ClassName PageViewAction
  13.  * @Description 记录网络访问量Action
  14.  * @struts2配置文件名 struts-test-modulePage-pageView.xml
  15.  * @spring3配置文件名 spring-test-modulePage-pageView.xml
  16.  * @mybatis3配置文件名 mybatis-test-modulePage-pageView.xml
  17.  * @表名 sys_page_view
  18.  * @author generate
  19.  * @date - 2015-02-10 15:33:10
  20.  * @version V1.0
  21.  */
  22. @SuppressWarnings(“serial”)
  23. @Controller(“pageViewAction”)
  24. @Scope(“prototype”)
  25. public class PageViewAction extends BaseAction<PageView> {
  26.     @Autowired
  27.     private PageViewService pageViewService;
  28.     private PageView pageView;
  29.     private String[] ids;
  30.     /**
  31.      * 新增或者修改记录
  32.      */
  33.     public void save() {
  34.         pageViewService.saveOrUpdate(pageView);
  35.         JSONOuter.writeBeanMsg(getPrintWriter(), pageView,”数据保存成功”);
  36.     }
  37.     /**
  38.      * 加载数据对象
  39.      */
  40.     public void load() {
  41.         PageView pageViewObj = pageViewService.getById( pageView.getId()  );
  42.         JSONOuter.writeBeanMsg(getPrintWriter(), pageViewObj);
  43.     }
  44.     /**
  45.      * 分页查询
  46.      */
  47.     public void pagelist() {
  48.         IGenericPage<PageView> iPage = pageViewService.findPageBy(
  49.                 pageView,
  50.                 this.getPage(),
  51.                 this.getRows(),
  52.                 this.getSidx(),
  53.                 this.getSord());
  54.         JSONOuter.writePage(getPrintWriter(), iPage);
  55.     }
  56.     /**
  57.      * 数据列表
  58.      */
  59.     public void list() {
  60.         List<PageView> list = pageViewService.findListBy(
  61.                 pageView, this.getSidx(), this.getSord());
  62.         JSONOuter.writeList(getPrintWriter(), list);
  63.     }
  64.     /**
  65.      * 批量删除记录
  66.      */
  67.     public void delete() {
  68.     String msg = ”";
  69.         if(ids!=null && ids.length>0){
  70.             int s = pageViewService.deleteByIds(ids);
  71.             msg = ”成功删除 ” + s + ” 条记录!!!”;
  72.         }else{
  73.             msg = ”删除失败,请选择要删除的记录!!!”;
  74.         }
  75.         JSONOuter.writeSuccessMsg(getPrintWriter(), msg);
  76.     }
  77.     /**
  78.      * 模型驱动,自动装配页面属性
  79.      */
  80.     public PageView getModel() {
  81.         pageView = new PageView();
  82.         return pageView;
  83.     }
  84.     public void setIds(String[] ids) {
  85.         this.ids = ids;
  86.     }
  87. }

 

 

service接口:PageViewService.java

[java] view plain copy

在CODE上查看代码片派生到我的代码片

  1. package com.liupengyuan.test.modulePage.pageView.service;
  2. import java.util.List;
  3. import com.liupengyuan.test.modulePage.pageView.model.PageView;
  4. import com.liupengyuan.framework.web.query.IGenericPage;
  5. /**
  6.  * @ClassName PageViewService
  7.  * @Description 记录网络访问量服务接口
  8.  * @struts2 配置文件名 struts-test-modulePage-pageView.xml
  9.  * @spring3 配置文件名 spring-test-modulePage-pageView.xml
  10.  * @mybatis3 配置文件名 mybatis-test-modulePage-pageView.xml
  11.  * @表名 sys_page_view
  12.  * @author generate
  13.  * @date - 2015-02-10 15:33:10
  14.  * @version V1.0
  15.  */
  16. public interface PageViewService {
  17.     /**
  18.      * 根据通过主键ID获取一个记录网络访问量实例
  19.      * @param id 记录网络访问量ID
  20.      * @return 记录网络访问量实例
  21.      */
  22.     public PageView getById(java.io.Serializable id);
  23.     /**
  24.      * 批量删除
  25.      * @param ids 要删除的记录网络访问量ID集合
  26.      * @return 删除成功的记录生活
  27.      */
  28.     public Integer deleteByIds(java.io.Serializable[] ids);
  29.     public Integer deleteById(java.io.Serializable ids);
  30.     /**
  31.      * 保持一个新增的记录网络访问量实例
  32.      * @param pageView 记录网络访问量
  33.      */
  34.     public void save(PageView pageView);
  35.     /**
  36.      * 保存一个修改的记录网络访问量实例
  37.      * @param pageView 记录网络访问量
  38.      */
  39.     public void update(PageView pageView);
  40.     /**
  41.      * 保存一个新增或修改的记录网络访问量实例
  42.      * @param pageView 记录网络访问量
  43.      */
  44.     public void saveOrUpdate(PageView pageView);
  45.     /**
  46.      * 分页查询
  47.      * @param param 查询参数
  48.      * @param currentPage 当前页码
  49.      * @param rows 每页记录行数
  50.      * @param sort 排序字段
  51.      * @param dir 排序方式、降序(desc)或升序(asc)
  52.      * @return 记录网络访问量实例集合
  53.      */
  54.     public IGenericPage<PageView> findPageBy(
  55.             PageView param,
  56.             int currentPage,
  57.             int rows,
  58.             String sort,
  59.             String dir);
  60.     /**
  61.      * 主要是配合分页查询返回总记录数
  62.      * @param param 主要查询参数封装在param中
  63.      * @return 记录数
  64.      */
  65.     public Integer getCountByParam(PageView param);
  66.     /**
  67.      * 不分页查询
  68.      * @param param 主要查询参数封装在param中
  69.      * @param sort 排序字段
  70.      * @param dir 排序方式、降序(desc)或升序(asc)
  71.      * @return 记录网络访问量实例集合
  72.      */
  73.     public List<PageView> findListBy(PageView param, String sort, String dir);
  74. }

 

 

service实现类:PageViewServiceImpl.java

[java] view plain copy

在CODE上查看代码片派生到我的代码片

  1. package com.liupengyuan.test.modulePage.pageView.service.impl;
  2. import java.util.List;
  3. import org.apache.commons.lang.StringUtils;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import com.liupengyuan.framework.web.query.IGenericPage;
  7. import com.liupengyuan.test.modulePage.pageView.dao.PageViewDao;
  8. import com.liupengyuan.test.modulePage.pageView.model.PageView;
  9. import com.liupengyuan.test.modulePage.pageView.service.PageViewService;
  10. /**
  11.  * @ClassName PageViewServiceImpl
  12.  * @Description 记录网络访问量服务实现类
  13.  * @struts2 配置文件名 struts-test-modulePage-pageView.xml
  14.  * @spring3 配置文件名 spring-test-modulePage-pageView.xml
  15.  * @mybatis3 配置文件名 mybatis-test-modulePage-pageView.xml
  16.  * @表名 sys_page_view
  17.  * @author generate
  18.  * @date - 2015-02-10 15:33:10
  19.  * @version V1.0
  20.  */
  21. @Service(“pageViewService”)
  22. public class PageViewServiceImpl implements PageViewService {
  23.     @Autowired
  24.     private PageViewDao pageViewDao;
  25.     /*
  26.      * (non-Javadoc)
  27.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#getById(java.io.Serializable)
  28.      */
  29.     public PageView getById(java.io.Serializable id) {
  30.         return pageViewDao.getById(id);
  31.     }
  32.     /*
  33.      * (non-Javadoc)
  34.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#deleteByIds(java.io.Serializable[])
  35.      */
  36.     public Integer deleteByIds(java.io.Serializable[] ids) {
  37.         return pageViewDao.deleteByIds(ids);
  38.     }
  39.     /*
  40.      * (non-Javadoc)
  41.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#deleteById(java.io.Serializable)
  42.      */
  43.     public Integer deleteById(java.io.Serializable id) {
  44.         return pageViewDao.deleteById(id);
  45.     }
  46.     /*
  47.      * (non-Javadoc)
  48.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#save(com.liupengyuan.test.modulePage.pageView.model.PageView)
  49.      */
  50.     public void save(PageView ob) {
  51.         pageViewDao.save(ob);
  52.     }
  53.     /*
  54.      * (non-Javadoc)
  55.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#update(com.liupengyuan.test.modulePage.pageView.model.PageView)
  56.      */
  57.     public void update(PageView ob) {
  58.         pageViewDao.update(ob);
  59.     }
  60.     /*
  61.      * (non-Javadoc)
  62.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#saveOrUpdate(com.liupengyuan.test.modulePage.pageView.model.PageView)
  63.      */
  64.     public void saveOrUpdate(PageView ob) {
  65.         if (ob != null) {
  66.             // 如果ID不为空说明是修改的实例,为更新操作
  67.             if (null != ob.getId() && StringUtils.isNotEmpty(String.valueOf(ob.getId()))) {
  68.                 pageViewDao.update(ob);
  69.             } else {
  70.                 pageViewDao.save(ob);
  71.             }
  72.         }
  73.     }
  74.     /*
  75.      * (non-Javadoc)
  76.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#findPageBy(com.liupengyuan.test.modulePage.pageView.model.PageView, int, int, java.lang.String, java.lang.String)
  77.      */
  78.     public IGenericPage<PageView> findPageBy(
  79.             PageView param,
  80.             int currentPage,
  81.             int rows,
  82.             String sort,
  83.             String dir) {
  84.         return pageViewDao.findPageBy(
  85.                 wrapParams(param), currentPage, rows, sort, dir);
  86.     }
  87.     /*
  88.      * (non-Javadoc)
  89.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#getCountByParam(com.liupengyuan.test.modulePage.pageView.model.PageView)
  90.      */
  91.     public Integer getCountByParam(PageView param) {
  92.         return pageViewDao.getCountBy(wrapParams(param));
  93.     }
  94.     /**
  95.      * (non-Javadoc)
  96.      * @see com.liupengyuan.test.modulePage.pageView.service.PageViewService#findListBy(com.liupengyuan.test.modulePage.pageView.PageView, java.lang.String, java.lang.String)
  97.      */
  98.     public List<PageView> findListBy(
  99.             PageView param,
  100.             String sort,
  101.             String dir) {
  102.         return pageViewDao.findListBy(
  103.                 wrapParams(param), sort, dir);
  104.     }
  105.     /**
  106.      * 为模糊查询前后加装%%
  107.      */
  108.     private PageView wrapParams(PageView param) {
  109.         if(param != null){
  110.             if(StringUtils.isNotEmpty(param.getRequestIp())){
  111.                 param.setRequestIp(“%”+param.getRequestIp()+”%”);
  112.             }
  113.             if(StringUtils.isNotEmpty(param.getSession())){
  114.                 param.setSession(“%”+param.getSession()+”%”);
  115.             }
  116.             if(StringUtils.isNotEmpty(param.getModule())){
  117.                 param.setModule(“%”+param.getModule()+”%”);
  118.             }
  119.         }
  120.         return param;
  121.     }
  122. }

DAO接口:PageViewDao.java

[java] view plain copy

在CODE上查看代码片派生到我的代码片

  1. package com.liupengyuan.test.modulePage.pageView.dao;
  2. import com.liupengyuan.framework.dao.IBaseGenericDAO;
  3. import com.liupengyuan.test.modulePage.pageView.model.PageView;
  4. /**
  5.  * @ClassName PageViewDao
  6.  * @Description 记录网络访问量DAO接口
  7.  * @struts2 配置文件名 struts-test-modulePage-pageView.xml
  8.  * @spring3 配置文件名 spring-test-modulePage-pageView.xml
  9.  * @mybatis3 配置文件名 mybatis-test-modulePage-pageView.xml
  10.  * @表名 sys_page_view
  11.  * @author generate
  12.  * @date - 2015-02-10 15:33:10
  13.  * @version V1.0
  14.  */
  15. public interface PageViewDao extends IBaseGenericDAO<PageView> {
  16. }

 

 

DAO实现类:PageViewDaoImpl.java

[java] view plain copy

在CODE上查看代码片派生到我的代码片

  1. package com.liupengyuan.test.modulePage.pageView.dao.impl;
  2. import org.springframework.stereotype.Repository;
  3. import com.liupengyuan.framework.dao.MybatisBaseGenericDAOImpl;
  4. import com.liupengyuan.framework.util.GeneratorKey;
  5. import com.liupengyuan.test.modulePage.pageView.dao.PageViewDao;
  6. import com.liupengyuan.test.modulePage.pageView.model.PageView;
  7. /**
  8.  * @ClassName PageViewDaoImpl
  9.  * @Description 记录网络访问量DAO实现类
  10.  * @struts2 配置文件名 struts-test-modulePage-pageView.xml
  11.  * @spring3 配置文件名 spring-test-modulePage-pageView.xml
  12.  * @mybatis3 配置文件名 mybatis-test-modulePage-pageView.xml
  13.  * @表名 sys_page_view
  14.  * @author generate
  15.  * @date - 2015-02-10 15:33:10
  16.  * @version V1.0
  17.  */
  18. @Repository(“pageViewDao”)
  19. public class PageViewDaoImpl
  20. extends MybatisBaseGenericDAOImpl<PageView>
  21. implements PageViewDao {
  22.     /**
  23.      * 生成UUID主键值。
  24.      * @param ob 记录网络访问量
  25.      */
  26.     public void generateId(PageView ob) {
  27.         //id
  28.         if(null == ob.getId() || ob.getId().length() == 0){
  29.             ob.setId(GeneratorKey.genaraId());
  30.         }
  31.     }
  32. }

 

 

model:PageView.java

[java] view plain copy

在CODE上查看代码片派生到我的代码片

  1. package com.liupengyuan.test.modulePage.pageView.model;
  2. /**
  3.  * @ClassName PageView
  4.  * @Description 记录网络访问量 实体(领域)对象
  5.  * @struts2 配置文件名 struts-test-modulePage-pageView.xml
  6.  * @spring3 配置文件名 spring-test-modulePage-pageView.xml
  7.  * @mybatis3 配置文件名 mybatis-test-modulePage-pageView.xml
  8.  * @表名 sys_page_view
  9.  * @author generate
  10.  * @date - 2015-02-10 15:33:10
  11.  * @version V1.0
  12.  */
  13. public class PageView implements java.io.Serializable {
  14.     /** id */
  15.     private java.lang.String id;
  16.     /**
  17.      * 获取id
  18.      * @return id
  19.      */
  20.     public java.lang.String getId() {
  21.         return this.id;
  22.     }
  23.     /**
  24.      * 设置id
  25.      */
  26.     public void setId(java.lang.String id){
  27.         this.id = id;
  28.     }
  29.     /** 用户IP */
  30.     private java.lang.String requestIp;
  31.     /**
  32.      * 获取用户IP
  33.      * @return 用户IP
  34.      */
  35.     public java.lang.String getRequestIp() {
  36.         return this.requestIp;
  37.     }
  38.     /**
  39.      * 设置用户IP
  40.      */
  41.     public void setRequestIp(java.lang.String requestIp){
  42.         this.requestIp = requestIp;
  43.     }
  44.     /** 记录会话ID */
  45.     private java.lang.String session;
  46.     /**
  47.      * 获取记录会话ID
  48.      * @return 记录会话ID
  49.      */
  50.     public java.lang.String getSession() {
  51.         return this.session;
  52.     }
  53.     /**
  54.      * 设置记录会话ID
  55.      */
  56.     public void setSession(java.lang.String session){
  57.         this.session = session;
  58.     }
  59.     /** 访问的模块 */
  60.     private java.lang.String module;
  61.     /**
  62.      * 获取访问的模块
  63.      * @return 访问的模块
  64.      */
  65.     public java.lang.String getModule() {
  66.         return this.module;
  67.     }
  68.     /**
  69.      * 设置访问的模块
  70.      */
  71.     public void setModule(java.lang.String module){
  72.         this.module = module;
  73.     }
  74.     /** 访问时间 */
  75.     private java.util.Date visitTime;
  76.     /**
  77.      * 获取访问时间
  78.      * @return 访问时间
  79.      */
  80.     public java.util.Date getVisitTime() {
  81.         return this.visitTime;
  82.     }
  83.     /**
  84.      * 设置访问时间
  85.      */
  86.     public void setVisitTime(java.util.Date visitTime){
  87.         this.visitTime = visitTime;
  88.     }
  89.     /** 访问数量 */
  90.     private java.lang.Integer visitCount;
  91.     /**
  92.      * 获取访问数量
  93.      * @return 访问数量
  94.      */
  95.     public java.lang.Integer getVisitCount() {
  96.         return this.visitCount;
  97.     }
  98.     /**
  99.      * 设置访问数量
  100.      */
  101.     public void setVisitCount(java.lang.Integer visitCount){
  102.         this.visitCount = visitCount;
  103.     }
  104. }

 

 

  • XML 配置文件

 

mybatis文件:mybatis-test-modulePage-pageView.xml

[html] view plain copy

在CODE上查看代码片派生到我的代码片

  1. <?xml version=”1.0″ encoding=”UTF-8″?>
  2. <!DOCTYPE mapper PUBLIC ”-//mybatis.org//DTD Mapper 3.0//EN” ”http://mybatis.org/dtd/mybatis-3-mapper.dtd”>
  3. <mapper namespace=”com.liupengyuan.test.modulePage.pageView.model.PageView”>
  4.     <resultMap id=”pageViewResultMap” type=”com.liupengyuan.test.modulePage.pageView.model.PageView”>
  5.         <!– id –>
  6.         <result column=”id” property=”id” jdbcType=”VARCHAR” />
  7.         <!– 用户IP –>
  8.         <result column=”request_ip” property=”requestIp” jdbcType=”VARCHAR” />
  9.         <!– 记录会话ID –>
  10.         <result column=”session” property=”session” jdbcType=”VARCHAR” />
  11.         <!– 访问的模块 –>
  12.         <result column=”module” property=”module” jdbcType=”VARCHAR” />
  13.         <!– 访问时间 –>
  14.         <result column=”visit_time” property=”visitTime” jdbcType=”TIMESTAMP” />
  15.         <!– 访问数量 –>
  16.         <result column=”visit_count” property=”visitCount” jdbcType=”INTEGER” />
  17.     </resultMap>
  18.     <!– 表名 –>
  19.     <sql id=”tableNameSql”>
  20.         sys_page_view
  21.     </sql>
  22.     <!– 用于select查询、insert的公用抽取的列 –>
  23.     <sql id=”commonSelectColumnsPrefix”>
  24.             id ,
  25.             request_ip ,
  26.             session ,
  27.             module ,
  28.             visit_time ,
  29.             visit_count
  30.     </sql>
  31.     <!– 按主键查找条件语句 –>
  32.     <sql id=”conditionOnlyId”>
  33.         id = #{id}
  34.     </sql>
  35.     <sql id=”mainSql”>
  36.         SELECT
  37.             <include refid=”commonSelectColumnsPrefix”/>
  38.         FROM
  39.             <include refid=”tableNameSql”/> p
  40.     </sql>
  41.     <sql id=”varSql”>
  42.         <where>
  43.             <if test=”requestIp!=null and requestIp!=””>and p.request_ip like #{requestIp} </if>
  44.             <if test=”session!=null and session!=””>and p.session like #{session} </if>
  45.             <if test=”module!=null and module!=””>and p.module like #{module} </if>
  46.         </where>
  47.     </sql>
  48.     <select id=”findPageBy” parameterType=”java.util.Map” resultMap=”pageViewResultMap”>
  49.         <include refid=”mainSql”/>
  50.         <include refid=”varSql”/>
  51.         <if test=”SORT != null and SORT != ””>
  52.             order by ${SORT}
  53.             <if test=”DIR != null and DIR != ””>
  54.                  ${DIR}
  55.             </if>
  56.         </if>
  57.     </select>
  58.     <select id=”getById” parameterType=”String” resultMap=”pageViewResultMap”>
  59.         <include refid=”mainSql”/>
  60.         where <include refid=”conditionOnlyId”/>
  61.     </select>
  62.     <select id=”getCountBy” parameterType=”java.util.Map” resultType=”INTEGER”>
  63.         SELECT
  64.             COUNT(*) AS C
  65.         FROM
  66.             <include refid=”tableNameSql”/> p
  67.         <include refid=”varSql”/>
  68.     </select>
  69.     <select id=”findListBy” parameterType=”java.util.Map” resultMap=”pageViewResultMap”>
  70.         <include refid=”mainSql”/>
  71.         <include refid=”varSql”/>
  72.         <if test=”SORT != null and SORT != ””>
  73.             order by ${SORT}
  74.             <if test=”DIR != null and DIR != ””>
  75.                  ${DIR}
  76.             </if>
  77.         </if>
  78.     </select>
  79.     <insert id=”save” parameterType=”com.liupengyuan.test.modulePage.pageView.model.PageView”>
  80.         insert into
  81.             <include refid=”tableNameSql”/>
  82.         (
  83.             <include refid=”commonSelectColumnsPrefix”/>
  84.         )
  85.         values
  86.         (
  87.             #{id, jdbcType=VARCHAR} ,
  88.             #{requestIp, jdbcType=VARCHAR} ,
  89.             #{session, jdbcType=VARCHAR} ,
  90.             #{module, jdbcType=VARCHAR} ,
  91.             #{visitTime, jdbcType=TIMESTAMP} ,
  92.             #{visitCount, jdbcType=INTEGER}
  93.         )
  94.     </insert>
  95.     <update id=”update” parameterType=”com.liupengyuan.test.modulePage.pageView.model.PageView”>
  96.         update
  97.             <include refid=”tableNameSql”/>
  98.         set
  99.             request_ip = #{requestIp, jdbcType=VARCHAR} ,
  100.             session = #{session, jdbcType=VARCHAR} ,
  101.             module = #{module, jdbcType=VARCHAR} ,
  102.             visit_time = #{visitTime, jdbcType=TIMESTAMP} ,
  103.             visit_count = #{visitCount, jdbcType=INTEGER}
  104.         where <include refid=”conditionOnlyId”/>
  105.     </update>
  106.     <delete id=”deleteByIds” parameterType=”Object[]“>
  107.         delete from <include refid=”tableNameSql”/>
  108.         where id in <foreach index=”index” item=”item” collection=”array” separator=”,” open=”(“ close=”)” >#{item}</foreach>
  109.     </delete>
  110.     <delete id=”deleteById” parameterType=”Object”>
  111.         delete from <include refid=”tableNameSql”/> where <include refid=”conditionOnlyId”/>
  112.     </delete>
  113. </mapper>

 

 

spring配置文件:spring-test-modulePage-pageView.xml

[html] view plain copy

在CODE上查看代码片派生到我的代码片

  1. <?xml version=”1.0″ encoding=”UTF-8″?>
  2. <beans xmlns=”http://www.springframework.org/schema/beans”
  3.     xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
  4.     xmlns:aop=”http://www.springframework.org/schema/aop”
  5.     xmlns:tx=”http://www.springframework.org/schema/tx”
  6.     xmlns:context=”http://www.springframework.org/schema/context”
  7.     xsi:schemaLocation=”
  8.             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  9.             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  10.             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
  11.             http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
  12.             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd”>
  13.     <context:component-scan base-package=”com.liupengyuan.test.modulePage.pageView.*” />
  14. </beans>

Struts2配置文件:struts-test-modulePage-pageView.xml

[html] view plain copy

在CODE上查看代码片派生到我的代码片

  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=”com.liupengyuan.test.modulePage.pageView.action.PageViewAction” extends=”struts-default” namespace=”/jsp/moduleWeb/pageView”>
  7.         <action name=”pageView_*”
  8.                 class=”pageViewAction”
  9.                 method=”{1}”>
  10.         </action>
  11.         <action name=”pageView”>
  12.             <result>/jsp/moduleWeb/pageView/pageView.jsp</result>
  13.         </action>
  14.     </package>
  15. </struts>

 

结束…