到这里已经写到第12篇了,前11篇基本上把Spring MVC主要的内容都讲了,如今就直接上一个项目吧,但愿能对有须要的朋友有一些帮助。html
1、首先看一下项目结构:前端
InfrastructureProjects:是抽取出的基础项目,主要封装了一些通用的操做。java
SpringMVC3Demo:就是管理系统所在的项目。mysql
WeiXinAPI:是以前作微信管理平台测试时封装一些操做,若是不须要把该项目移除便可。web
注:项目的前端UI框架用的是国外的一个基于Bootstrap框架的开发的Demo,如不须要替换为本身熟悉的UI框架便可。正则表达式
2、实现的功能:spring
登陆:sql
注册:chrome
首页:数据库
用户管理:
帐户绑定:
角色管理:
角色受权:
权限管理:
组织机构管理:
这是权限添加界面:
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方法改成如下代码:
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)); } }*/ }
原来代码里面注释的部分才是最终的代码,下面的才是应该被注释的,不知道为何变成之前的版本了。