一直想写这篇文章,前段时间痴迷于Javascript、NodeJs、AngularJS,做了大量的研究,对前后端交互有了更深层次的认识。
今天抽个时间写这篇文章,我有预感,这将是一篇很详细的文章,详细的配置,详细的注释,看起来应该很容易懂。
用最合适的技术去实现,并不断追求最佳实践。这就是架构之道。
希望这篇文章能给你们带来一些帮助,同时希望你们可以为这个项目贡献你的想法。
源码地址:https://github.com/Eliteams/quick4j 点击打开
源码地址:https://github.com/Eliteams/quick4j 点击打开
源码地址:https://github.com/Eliteams/quick4j 点击打开
看我们的项目结构:
是一个典型的Maven 项目 :
src/main/Java:存放java源文件
src/main/resources:存放程序资源、配置文件
src/test/java:存放测试代码文件
src/main/webapp:web根目录
pom.xml : maven项目配置文件,管理依赖,编译,打包
主要的后端架构:spring + Spring MVC + Mybatis + Apache Shiro
前端界面主要使用Metronic 模板,
先看我们搭建完成,跑起来的效果,这样你才有兴趣看下去:
你可以 在github 上 checkout quick4j项目 查看 ,并跟下面步骤 来搭建:
强烈建议你,checkout https://github.com/Eliteams/quick4j ,在本地跑起来,再试着自己搭建框架
1、首先创建 maven 项目 ,用 idea 、eclipse 或 mvn 命令行都行
2、配置 pom.xml ,添加框架依赖
4.0.0 com.eliteams quick4jwar 1.0.0 quick4j App https://github.com/starzou/quick4j quick4j org.mybatis.generator mybatis-generator-maven-plugin${plugin.mybatis.generator} ${mybatis.generator.generatorConfig.xml} true true org.apache.maven.plugins maven-compiler-plugin${plugin.maven-compiler} ${project.build.jdk} ${project.build.jdk} ${project.build.sourceEncoding} src/main/resources ***.xml true src/main/java ***.xml true UTF-8 zh_CN 1.7 ${basedir}/src/test/resources/generatorConfig.xml file:///${basedir}/src/test/resources/generatorConfig.properties 1.3.1 3.1 4.11 4.0.2.RELEASE 3.2.2 1.2.2 5.1.30 9.1-901.jdbc4 1.6.6 1.2.12 4.1.2 1.9.13 0.9.1.2 1.0.5 7.0.53 1.2 1.0 3.1 1.2.3 1.3.1 1.9 3.3 1.6.124.0.18.Final 5.1.1.Final junit junit${junit.version} org.springframework spring-core${spring.version} org.springframework spring-web${spring.version} org.springframework spring-oxm${spring.version} org.springframework spring-tx${spring.version} org.springframework spring-jdbc${spring.version} org.springframework spring-webmvc${spring.version} org.springframework spring-aop${spring.version} org.springframework spring-context-support${spring.version} org.springframework spring-test${spring.version} org.mybatis mybatis${mybatis.version} org.mybatis mybatis-spring${mybatis.spring.version} mysql mysql-connector-java${mysql.connector.version} com.alibaba druid${druid.version} org.codehaus.jackson jackson-mapper-asl${jackson.version} log4j log4j${log4j.version} org.slf4j slf4j-api${slf4j.version} org.slf4j slf4j-log4j12${slf4j.version} javax.servlet javax.servlet-api3.0.1 provided javax.servlet jstl${jstl.version} commons-fileupload commons-fileupload${commons.fileupload.version} org.apache.httpcomponents httpclient${httpclient.version} commons-codec commons-codec${commons.codec.version} commons-net commons-net${commons.net.version} commons-logging commons-logging1.1.3 commons-collections commons-collections3.2.1 com.google.collections google-collections${google.collections.version} cglib cglib-nodep${cglib.version} org.apache.shiro shiro-spring${shiro.version} org.apache.shiro shiro-ehcache${shiro.version} org.apache.shiro shiro-core${shiro.version} org.apache.shiro shiro-web${shiro.version} org.apache.shiro shiro-quartz${shiro.version} org.aspectj aspectjweaver${aspectj.version} org.aspectj aspectjrt${aspectj.version} org.hibernate hibernate-validator${hibernate.validator.version} io.netty netty-all${netty.version} org.mybatis.generator mybatis-generator-core1.3.2 jar test
3、配置web.xml
web.xml是一个项目的核心,看看它的一些配置:
配置 ContextLoaderListener 监听器
配置Spring字符编码过滤器
配置shiro 安全过滤器
配置Spring MVC 核心控制器 DispatcherServlet
配置一些页面
spring 和 apache shiro 是由一个 ContextLoaderListener 监听器 加载的配置文件,并初始化
contextConfigLocation classpath*:applicationContext.xml classpath*:applicationContext-shiro.xml org.springframework.web.context.ContextLoaderListener encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true encodingFilter ; ; ; ; ; ; CREATE DATAbase `quick4j` ; USE `quick4j`; DROP TABLE IF EXISTS `permission`; CREATE TABLE `permission` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '权限id', `permission_name` varchar(32) DEFAULT NULL COMMENT '权限名', `permission_sign` varchar(128) DEFAULT NULL COMMENT '权限标识,程序中判断使用,如"user:create"', `description` varchar(256) DEFAULT NULL COMMENT '权限描述,UI界面显示使用', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='权限表'; insert into `permission`(`id`,`permission_name`,`permission_sign`,`description`) values (1,'用户新增','user:create',NULL); DROP TABLE IF EXISTS `role`; CREATE TABLE `role` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '角色id', `role_name` varchar(32) DEFAULT NULL COMMENT '角色名', `role_sign` varchar(128) DEFAULT NULL COMMENT '角色标识,程序中判断使用,如"admin"', `description` varchar(256) DEFAULT NULL COMMENT '角色描述,UI界面显示使用', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='角色表'; insert into `role`(`id`,`role_name`,`role_sign`,`description`) values (1,'admin','admin','管理员'); DROP TABLE IF EXISTS `role_permission`; CREATE TABLE `role_permission` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '表id', `role_id` bigint(20) unsigned DEFAULT NULL COMMENT '角色id', `permission_id` bigint(20) unsigned DEFAULT NULL COMMENT '权限id', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='角色与权限关联表'; insert into `role_permission`(`id`,`role_id`,`permission_id`) values (1,2,1); DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户id', `username` varchar(50) DEFAULT NULL COMMENT '用户名', `password` char(64) DEFAULT NULL COMMENT '密码', `state` varchar(32) DEFAULT NULL COMMENT '状态', `create_time` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='用户表'; insert into `user`(`id`,`username`,`password`,`state`,`create_time`) values (1,'starzou','8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92',NULL,'2014-07-17 12:59:08'); DROP TABLE IF EXISTS `user_role`; CREATE TABLE `user_role` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '表id', `user_id` bigint(20) unsigned DEFAULT NULL COMMENT '用户id', `role_id` bigint(20) unsigned DEFAULT NULL COMMENT '角色id', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='用户与角色关联表'; insert into `user_role`(`id`,`user_id`,`role_id`) values (1,1,1); ; ; ; ;
以上所述是小编给大家介绍的基于Spring + Spring MVC + Mybatis 高性能web构建实例详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!



