zoukankan      html  css  js  c++  java
  • SpringMVC(12)完结篇 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现

    到这里已经写到第12篇了,前11篇基本上把Spring MVC主要的内容都讲了,现在就直接上一个项目吧,希望能对有需要的朋友有一些帮助。

    一、首先看一下项目结构:

    1

    InfrastructureProjects:是抽取出的基础项目,主要封装了一些通用的操作。

    SpringMVC3Demo:就是管理系统所在的项目。

    WeiXinAPI:是之前做微信管理平台测试时封装一些操作,如果不需要把该项目移除即可。

    注:项目的前端UI框架用的是国外的一个基于Bootstrap框架的开发的Demo,如不需要替换为自己熟悉的UI框架即可。

     

    二、实现的功能:

    登录:

    2014-05-27 13^%42^%12的屏幕截图

    注册:

    2014-05-27 13^%42^%42的屏幕截图

    首页:

    2014-05-27 13^%43^%05的屏幕截图

    用户管理:

    2014-05-27 13^%44^%13的屏幕截图

    账户绑定:

    2014-05-27 13^%44^%44的屏幕截图

    角色管理:

    2014-05-27 13^%44^%54的屏幕截图

    角色授权:

    2014-05-27 13^%45^%20的屏幕截图

    权限管理:

    2014-05-27 13^%45^%55的屏幕截图

    组织机构管理:

    2014-05-27 13^%46^%08的屏幕截图

    这是权限添加界面:

    2014-05-27 13^%46^%43的屏幕截图

     

    PS:

    1.关于权限配置:权限配置是按正则表达式匹配的,可参见下表是我现在数据库里面的权限配置:

    权限配置

     

    2.在Hibernate配置文件比如Role.hbm.xml中,authorities一对多我这里配的是lazy="false",是因为在用户登录时检查权限肯定要获取对应Role下的所有authorities,所以没必要开lazy加载,但是如果你要添加其它功能是,请根据需求来决定是否开lazy,比如账户—>订单这样的就需要开lazy。关于Hibernate网上有很多资料可供参考,这里推荐一下刘冬大哥写的NHibernate系列文章:http://www.cnblogs.com/GoodHelper/category/214139.html可以作为学习Hibernate的参考。

     

    3.由于OpenSessionInView会有性能上的损失,所以项目没有开OpenSessionInView,而且Hibernate的事务是配置到Service的,所以请在Service层返回数据时准备好所有需要的数据,否则在Controller或View中想调用lazy加载数据会抛出事务已关闭的异常。

     

    4.运行项目时最好用新的chrome或firefox浏览器,Bootstrap3不支持IE8以下浏览器,而且用IE的话要想完全显示出Bootstrap3的效果则至少IE10.

     

    5.由于最近事情比较多,项目的国际化还没来得及添加,可以根据系列(8)所讲的内容自行添加也算做练手(^.^)~~~

     

    6.项目引用的jar包是用的User Library添加进的,在把项目解压到本地时有可能里面的引用的路径和我机器上的不一样,如果包路径不正确请按包在自己机器上的路径进行更改。

     

    代码下载:http://pan.baidu.com/s/1sjwdPLz 

    总共70多MB,但是别激动,项目没那么大主要是找需要的包时,下载的zip文件解压后会有一堆包文件,很多是没用到的,我没删都放在Dependence文件夹下面了,只是在项目中对需要的包添加了引用。

     

    数据库文件下载:http://pan.baidu.com/s/1i33gczN

     

    PPS:因为这个系统有2个项目,一个是通用的基础项目,一个是网站,当时为了管理包的方便所以用了User Library的方式添加项目中需要的包,前些时间感觉电脑越来越慢了,就把电脑中的虚拟机卸载掉了,只保留的项目的源码,然后有朋友告诉我项目导入后User Library里面内容是空的,之后我把项目导入到我win系统中的eclipse中也发现User Library没有内容(又遇到了一个坑,还是我用的方式不对?)。所以,不知道User Library引用什么包的朋友可以参考第11篇的项目源码,里面引用的包是直接添加到项目里面的,当然第11篇引用的包是少于这个项目的,不过少引用的包根据提示到Dependence文件夹下找到后添加即可,另:Infrastructure Projects中引用的User Library和SpringMVC3 Demo引用的是不同的,需要注意。

     

    PPPS:贴一下一个朋友调试成功项目所引用的包(我机器的开发环境没有了,懒得折腾了,原谅我的懒惰~),给需要的做一个参考:

    InfrastructureProjects项目:

    /InfrastructureProjects/lib/antlr-2.7.7.jar
    /InfrastructureProjects/lib/dom4j-1.6.1.jar
    /InfrastructureProjects/lib/hibernate-commons-annotations-4.0.2.Final.jar
    /InfrastructureProjects/lib/hibernate-core-4.2.8.Final.jar
    /InfrastructureProjects/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar
    /InfrastructureProjects/lib/javassist-3.18.1-GA.jar
    /InfrastructureProjects/lib/jboss-logging-3.1.0.GA.jar
    /InfrastructureProjects/lib/jboss-transaction-api_1.1_spec-1.0.1.Final.jar
    /InfrastructureProjects/lib/jstl.jar
    /InfrastructureProjects/lib/spring-beans-3.2.5.RELEASE
    /InfrastructureProjects/lib/standard.jar

     

    SpringMvc3Demo项目:

    antlr-2.7.7.jar
    aopalliance-1.0.jar
    aspectjrt.jar
    aspectjweaver.jar
    commons-beanutils-1.8.0.jar
    commons-collections-3.2.1.jar
    commons-fileupload-1.3.1.jar
    commons-io-2.4.jar
    commons-lang-2.5.jar
    commons-logging-1.1.3.jar
    dom4j-1.6.1.jar
    ezmorph-1.0.6.jar
    hibernate-commons-annotations-4.0.2.Final.jar
    hibernate-core-4.2.8.Final.jar
    hibernate-jpa-2.0-api-1.0.1.Final.jar
    hibernate-validator-4.3.1.Final.jar
    hibernate-validator-annotation-processor-4.3.1.Final.jar
    jackson-core-asl-1.9.13.jar
    jackson-mapper-asl-1.9.13.jar
    javassist-3.18.1-GA.jar
    jboss-logging-3.1.0.CR2.jar
    jboss-logging-3.1.0.GA.jar
    jboss-transaction-api_1.1_spec-1.0.1.Final.jar
    joda-time-2.3.jar
    json-lib-2.4-jdk15.jar
    jstl.jar
    mysql-connector-java-5.1.10.jar
    proxool-0.9.1.jar
    proxool-cglib.jar
    spring-aop-3.2.5.RELEASE.jar
    spring-aop-3.2.5.RELEASE-javadoc.jar
    spring-aop-3.2.5.RELEASE-sources.jar
    spring-aspects-3.2.5.RELEASE.jar
    spring-aspects-3.2.5.RELEASE-javadoc.jar
    spring-aspects-3.2.5.RELEASE-sources.jar
    spring-beans-3.2.5.RELEASE.jar
    spring-beans-3.2.5.RELEASE-javadoc.jar
    spring-beans-3.2.5.RELEASE-sources.jar
    spring-build-src-3.2.5.RELEASE.jar
    spring-context-3.2.5.RELEASE.jar
    spring-context-3.2.5.RELEASE-javadoc.jar
    spring-context-3.2.5.RELEASE-sources.jar
    spring-context-support-3.2.5.RELEASE.jar
    spring-context-support-3.2.5.RELEASE-javadoc.jar
    spring-context-support-3.2.5.RELEASE-sources.jar
    spring-core-3.2.5.RELEASE.jar
    spring-core-3.2.5.RELEASE-javadoc.jar
    spring-core-3.2.5.RELEASE-sources.jar
    spring-expression-3.2.5.RELEASE.jar
    spring-expression-3.2.5.RELEASE-javadoc.jar
    spring-expression-3.2.5.RELEASE-sources.jar
    spring-instrument-3.2.5.RELEASE.jar
    spring-instrument-3.2.5.RELEASE-javadoc.jar
    spring-instrument-3.2.5.RELEASE-sources.jar
    spring-instrument-tomcat-3.2.5.RELEASE.jar
    spring-instrument-tomcat-3.2.5.RELEASE-javadoc.jar
    spring-instrument-tomcat-3.2.5.RELEASE-sources.jar
    spring-jdbc-3.2.5.RELEASE.jar
    spring-jdbc-3.2.5.RELEASE-javadoc.jar
    spring-jdbc-3.2.5.RELEASE-sources.jar
    spring-jms-3.2.5.RELEASE.jar
    spring-jms-3.2.5.RELEASE-javadoc.jar
    spring-jms-3.2.5.RELEASE-sources.jar
    spring-orm-3.2.5.RELEASE.jar
    spring-orm-3.2.5.RELEASE-javadoc.jar
    spring-orm-3.2.5.RELEASE-sources.jar
    spring-oxm-3.2.5.RELEASE.jar
    spring-oxm-3.2.5.RELEASE-javadoc.jar
    spring-oxm-3.2.5.RELEASE-sources.jar
    spring-struts-3.2.5.RELEASE.jar
    spring-struts-3.2.5.RELEASE-javadoc.jar
    spring-struts-3.2.5.RELEASE-sources.jar
    spring-test-3.2.5.RELEASE.jar
    spring-test-3.2.5.RELEASE-javadoc.jar
    spring-test-3.2.5.RELEASE-sources.jar
    spring-tx-3.2.5.RELEASE.jar
    spring-tx-3.2.5.RELEASE-javadoc.jar
    spring-tx-3.2.5.RELEASE-sources.jar
    spring-web-3.2.5.RELEASE.jar
    spring-web-3.2.5.RELEASE-javadoc.jar
    spring-web-3.2.5.RELEASE-sources.jar
    spring-webmvc-3.2.5.RELEASE.jar
    spring-webmvc-3.2.5.RELEASE-javadoc.jar
    spring-webmvc-3.2.5.RELEASE-sources.jar
    spring-webmvc-portlet-3.2.5.RELEASE.jar
    spring-webmvc-portlet-3.2.5.RELEASE-javadoc.jar
    spring-webmvc-portlet-3.2.5.RELEASE-sources.jar
    standard.jar
    validation-api-1.0.0.GA.jar

     

    PPPPS:请把InfrastructureProjects项目中ChainEntityDao类中的setLevelCode方法改为以下代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    protected void setLevelCode(EntityType entity) throws ValidatException {
            PKType id=(PKType)super.getSession().save(entity);
            if(entity.getParent()==null){
                entity.setLevelCode(id.toString());
                super.getSession().update(entity);
            }
            else{
                EntityType parentEntity=super.get(entity.getParent().getId());
                if(parentEntity==null)
                    throw new ValidatException("The parent does not exist!");
                else{
                    entity.setLevelCode(parentEntity.getLevelCode()+","+id.toString());
                    super.getSession().update(entity);
                }
            }
             
            /*DecimalFormat df = new DecimalFormat( "000" );
            EntityType maxLevelCodeEntity;
            if(entity.getParent()==null)
                maxLevelCodeEntity=getMaxLevelCodeExceCurrentEntity(null, entity.getId());
            else
                maxLevelCodeEntity=getMaxLevelCodeExceCurrentEntity(entity.getParent().getId(), entity.getId());
             
            if(maxLevelCodeEntity==null){
                if(entity.getParent()==null)
                    entity.setLevelCode(df.format(1));
                else
                    entity.setLevelCode(entity.getParent().getLevelCode()+df.format(1));
            }
            else{          
                String maxLevelCodeStr=maxLevelCodeEntity.getLevelCode();
                int maxLevelCode=Integer.parseInt(maxLevelCodeStr.substring(maxLevelCodeStr.length()-3, maxLevelCodeStr.length()));
                if(maxLevelCode+1>999)
                    throw new ValidatException("The levelcode exceeds the maximum of 999!");
                else{
                    if(entity.getParent()==null)
                        entity.setLevelCode(df.format(maxLevelCode+1));
                    else
                        entity.setLevelCode(entity.getParent().getLevelCode()+df.format(maxLevelCode+1));
                }
            }*/    
        }

      原来代码里面注释的部分才是最终的代码,下面的才是应该被注释的,不知道为什么变成以前的版本了。

  • 相关阅读:
    greenplum日常维护手册
    Android UI界面基本属性 大全
    Listview 选项按下去黑了所有按钮的解决方法 ——android:cacheColorHint=“#00000000”
    【转】Android应用程序模块详解
    android退出有多个activity的应用
    启动模式"singleTask"和FLAG_ACTIVITY_NEW_TASK具有不同的行为!
    Android 按两次back键退出 效率最高版
    【转】跑马灯效果
    Sundy笔记__Git版本控制
    如果你想用对话框代替一个activity的话,可以设置activity的主题属性
  • 原文地址:https://www.cnblogs.com/love-omnus/p/4196588.html
Copyright © 2011-2022 走看看