关于ss3扩展框架

原文可以去springside的论坛上找。
我的思路如下:
一、增加一套基于EXTJS的控件
     我感觉可以通过增加Struts2的一个theme,干脆叫做ext_xhtml,可以参考ajax theme,做一套。
     控件包括:
    1、tree可以支持拖拉,编辑还是权限,在基本树的基础上扩展为用户、角色、部门选择树。
    2、grid应该支持右键菜单,右键菜单中包括编辑、打开、删除以及其他定制操作,
         当然支持shift、ctrl多选,多选和单选后,右键菜单是不一致的。
    3、表单。
         3.1 富文本编辑。
     3.2 日期选择控件。
         3.3 BeanEditForm,功能类似Tapestry 5的BeanEditForm,
             3.3.1 通过property设置那些属性编辑、那些不需要;
             3.3.2 通过Model的property的类型和JPA Annotation,自动选择input type而且自动增加类型validation。
          属性类型和input type 对应如下:
                 @Basci,String => text
                 @Basci,long,int、float等数据类型 => text
                 @one-to-many等数据类型 => select
                或者(option="id",value="name")需要实现IEntity和IName,必须有id,name属性
                或者自定义实现ISelectModel
                 @Basci,date、time等日期类型    =>日期选择控件
                 @lob,byte[] =>file
                 @lob,String =>富文本编辑
                 其他 =>定制
         3.4 FileUpload,文件上传主要需要统一考虑性能和存储管理问题,最好增加Cache.
             3.4.1 文件上传流程:文件先放在Cache中,然后通过JMS异步写入到数据库中。
             3.4.2 文件下载流程:先从Cache中读文件,Cache如果没有,从数据库中读,并写入到cache中。
    4、struts2支持json
       4.1 增加JSON interrupter
       4.2 增加JSON Result
       4.3 基于Json-lib(http://json-lib.sourceforge.net/)
    5、工具条
       一般来说,每个gird都带有一个工具条。包括统一查询、新建等快捷键。
       
二、支持Restful 2
    2.1 URL路由规则。在StrutsEntityAction中实现index、view、edit、editNew、create、update、remove方法就可以。
子类一般无需实现,但留有回调就可以。路由规则如下:
          GET: /groupId/7/user          => method="index" ,groupId=7           =>listUser.jsp
          GET: /groupId/7/user/5       => method="view", id=5 ,groupId=7    =>viewUser.jsp
          GET: /groupId/7/user/5!edit => method="edit", id=5 ,groupId=7     =>editUser.jsp
          GET: /groupId/7/user/new   => method="editNew" ,groupId=7       =>newUser.jsp
          POST: /groupId/7/user        =>    method="create" ,groupId=7        =>listUser.jsp
          PUT: /groupId/7/user/5       =>  method="update",id=5 ,groupId=7  =>listUser.jsp
          DELETE: /user/5                       => method="remove"                                 =>listUser.jsp
          DELETE: /id/1/id/2/id/3/user                       => method="remove"                                 =>listUser.jsp (批量删除)


    2.2  在StrutsEntityAction,增加getHelper,实现ROR的部分help功能.
         2.2.1 url helper。public String url(String action, String... params);
           比如<s:set name="thisUrl" value="helper.url('user','groupId=2','roleId=5')" />
     2.2.2 获得参数的功能;这方面比动态语言稍微不方便一点。
           helper.getParam("groupId").toString();
           helper.getParam("selectUserIds").toList();//比如客户在用户表中,一次选择多个用户。
            不过在JSP中也很简单。
               <c:set var="groupId" value="${params.groupId}" />

三、零配置
    3.1 Struts2的零配置。通过Annotation和Restful2ActionMapper和CodeBehind。
      3.1.1 需要修改Struts2的源码(ClasspathConfigurationProvider),支持wizard功能。(无奈的办法)
      3.1.2 增加类似Restful2ActionMapper,CodeBehind功能的RuleActionMapper和RuleCodeBehind支持动态路由规则。
    3.2 Spring的零配置. 基于sannotations(http://sannotations.sourceforge.net/)。
        需要修改源码来支持parent和abstract属性。(无奈的办法)
    3.3 JPA的零配置.比较容易做到。
四、DAO
    4.1 dao采用CRUD GenericDAO模式.
       4.1.1 参考文章
          http://forum.springframework.org/showthread.php?p=120962
      http://www-128.ibm.com/developerworks/java/library/j-genericdao.html
      http://www.ibm.com/developerworks/cn/java/j-genericdao.html
    4.2 增加 JPA 的DSL Criteria Style api。Hibernate的Criteria不太易用。
       这方面BBA 96 这个开源项目做的很不错。不过可以再优化。基本思路如下:
4.2.1 简单的
   List users = GenericDAO.find(User.class,"groups:g.name","开发部")
4.2.2 复杂的
Criterion criterion =  Criterions.select(distinct(),count(),"g.name")
    .and(
         in("groups:g.name", "开发部","测试部","人事部","行政部门").eq("roles::r.name", "admin")
    ).or(
        eq("disable", true).gt("menus.m",1)
    )
    .group("g.name")
.having(gt(count(),1))
    .order(asc("createtime"));

//这个只是例子,
    List users = GenericDAO.find(User.class,criterion)

     介绍以下:
     4.2.2.1、"groups:g.name"是用户和部门内连接,g是部门的别名,g.name是部门的name属性
4.2.2.2、"roles::r.name"是用户和角色左连接,r是角色的别名,r.name是角色的name属性
4.2.2.3、目前只支持内连接和左外连接,其他连接在实际应用中一般极少用到.如果碰到这种情况,你可以试试去买彩票了。^_^
4.2.2.4、如果没有select方法,那么就是select *。and、in、or 、eq、gt、group、having、order都可以没有,根据情况而定。
4.2.2.5、支持eq、ne、le、ge、gt、lt、between、in、like、ilike等操作。

4.2.3 支持QBE
    User user = new User();
    List<User> Users = UserDao.find(like(User).excludeProperty("name"));

4.2.4 支持智能行数计算
   count(criterion),具体做法就是去掉group和order,
   然后在select count(o) from (去掉group和order的JPA QL) o。

4.2.5 支持常用MODEL
   4.2.5.1 主键统一名称为id,类型为Long的EntityImpl  implement IEntity
           public Long getId();
           public void setId(Long id);
   4.2.5.2 具有名称属性的NameEntityImpl extends EntityImpl implement IName
          public String getName();
          public void   setName(String name);
   4.2.5.3 名称唯一的UniqueNameEntityImpl extends NameEntityImpl implement IUniqueName
   4.2.5.4 有创建和更新时间,RecordableEntityImpl extends EntityImpl implement IRecordable
   4.2.5.5 当然都是各种接口。比如说,RecordableUniqueEntity extends UniqueNameEntityImpl  implement IRecordable

五、Service
    5.1 增加BaseEntityManager,其他Entity Service来继承这个BaseEntityManager
    5.2 组件,比如说compass、jbossrules、jbpm等应该在这个层次上定义
      SearchManager,RuleManager,WorkFlowManager,CacheManager,SecurityManager
    5.3 不能光看到ROR开发效率高,但同时也要看到ROR复用程度并不是很高。当然只是我个人意见,ROR fans别用砖头砸我。^_^
    5.4 增加异类关联。有点像@hibernate.any,不是一般的1:n或者m:n关联。实际情况很常见。
    而且就是hibernate.any也不能做到双向关联。
        比如说表单和工作流实例的关系、表单和附件的关系,日志和被记录实体的关系

六、增强测试
   6.1 基于Testng。junit无法实现测试方法的依赖关系。
   6.2 做各种测试基类。比如AbstractBaseManagerTests、BaseSearchManagerTests、BaseRuleManagerTests。
   6.3 坚持Pragmatic风格的测试。减少mock测试。毕竟我们是给他人提供框架的人。
       框架本身可以给二次开发人员提供mock测试。
  
七、项目管理
   7.1 做持续继承。可以通过CiruseControl,建议continuum更好。
   7.2 做单元测试覆盖率.
   7.3 彻底maven2,不要看到任何ant target。开发maven2 Mojo相当easy.

我的E-Mail: [email protected]

你可能感兴趣的:(json,jsp,框架,Hibernate,jpa)