配色: 字号:
原创SpringMvc+Mybatis+Redis框架
2016-11-07 | 阅:  转:  |  分享 
  
原创SpringMvc+Mybatis+Redis框架

框架运行环境:

Maven版本:3.3.9

Eclipse版本:MARS.2

JDK版本:1.8

Tocat版本:8.0.36

框架结构:框架全采用maven管理所以源码只有180KB左右要是不会Maven就请自行补习



annotation:自定义注解实现的类似于shiro的权限但是比较简单不喜勿喷没shiro强大但是比他简单然后自己结合RBAC+Redis+Intercept技术实现的为什么没用shiro并不是shiro不强大只是不太喜欢那么复杂的用法虽然已经很简单了我是懒得出奇的人不过还是建议大家多去学习shiro这个权限框架毕竟连spring都推荐使用ShiroRBAC是一个数据库的设计模型简单理解为:用户-角色-权限-资源这里不再多说有个网友帖子写得不错拦截器什么滴也不多说spring的核心之一

entity:实体类的父类很简单自己看源码就行

log4j:这里重写了log4j的SMTPAppender这个类首先说说这个类是干嘛的他是用来发送邮件的当报错时邮件通知管理员,具体的请参考我的另一篇博客,上面有详细介绍

mapper:所有mapper的父类默认提供了几个常用的方法

message:提示语相关的东西都不知道咋描述就是为了代码中不允许有一个中文和硬编码的存在当然自己也可以改改实现国际化

result:针对结果的格式的统一封装题外话:这个框架完全是为了提供接口而生所以很多什么页面跳转什么滴都没做只做了返回json这块连异常都封装成JSon了

tools:看名字就知道一些常用的工具类有什么身份证、经纬度、日期计算、DES和RSA加密、MD5之类的东西具体请看代码类注解我觉得我注解已经很多了



redis:这里重写了spring-data-redis里面的RedisCache、RedisCachemanager两个类和封装了一些其他的包目的就是为了实现redis的自动续期和单用户登录功能(一个用户同时只能在一个地方登录)如果需要实现不同平台的单用户登录需要自己小改一下在缓存中多加个平台标识就行了

butler:这是web项目名字不必纠结介绍下包的作用

service:系统的一些服务类这里只有定时任务和Springmail邮件推送服务

system:这个看里面的包就知道干嘛用的了就说说exception和interception这两个一个是全局异常一个是什么实体类校验权限等拦截器



框架的大致结构就介绍到这里下面说一声配置的xml

web.xml

[html]viewplaincopy在CODE上查看代码片派生到我的代码片




xmlns="http://xmlns.jcp.org/xml/ns/javaee"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

version="3.1">

butler





contextConfigLocation



classpath:applicationContext.xml,

classpath:spring-.xml











org.springframework.web.util.IntrospectorCleanupListener









org.springframework.web.context.ContextLoaderListener









CharacterEncoding

org.springframework.web.filter.CharacterEncodingFilter



encoding

UTF-8







CharacterEncoding

/







spring

org.springframework.web.servlet.DispatcherServlet



contextConfigLocation

classpath:spring-mvc.xml



1









HttpMethodFilter

org.springframework.web.filter.HttpPutFormContentFilter





HttpMethodFilter

spring





spring

/







接下来是Spring的主配置文件applicationContext.xml

[html]viewplaincopy在CODE上查看代码片派生到我的代码片




xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:cache="http://www.springframework.org/schema/cache"xmlns:c="http://www.springframework.org/schema/c"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd

http://www.springframework.org/schema/cache

http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">

















classpath:conf.properties

































































































































































这里说一说有个数据库加密的东西在这里

[html]viewplaincopy在CODE上查看代码片派生到我的代码片









classpath:conf.properties







意思就是用DBConfigurer这个类来解密conf.properties这个文件内的几个配置就是采用了des加密解密主要为了防止配置文件泄露数据库的信息暴露如果不用直接注释掉就可以使用明文了稍后会把properties相关文件贴出来

接下来是spring-mvc.xml

[html]viewplaincopy在CODE上查看代码片派生到我的代码片




xmlns:aop="http://www.springframework.org/schema/aop"xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"xmlns:task="http://www.springframework.org/schema/task"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd

http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.1.xsd">



































































接下来是spring-mail.xml:这是用来配置SpringMail发件人信息的jdk8发布出去原因和解决方案请看点击打开链接

[html]viewplaincopy在CODE上查看代码片派生到我的代码片




xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation=www.shanxiwang.net"

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd">



































${mail.smtp.auth}



${mail.smtp.timeout}



javax.net.ssl.SSLSocketFactory











接下来是spring-redis.xml:这是配置redis的东西

[html]viewplaincopy在CODE上查看代码片派生到我的代码片




xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:cache="http://www.springframework.org/schema/cache"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/cache

http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">





























































































接下来日志的xml也可以使用properties为毛我这里用xml具体原因请参考上文说的关于日志的文章

[html]viewplaincopy在CODE上查看代码片派生到我的代码片



















































































































































































































































































最后一个butler.xml:权限部分注释了想要测试放开取消注释即可

[html]viewplaincopy在CODE上查看代码片派生到我的代码片




xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd

http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd">

















WriteMapNullValue

WriteNullStringAsEmpty

































classpath:org/system/config/valid



















最后是conf.properties

这里加密的几个对应得明文分别是

url:jdbc:MySQL://localhsot:3306/butler?useUnicode=true&characterEncoding=utf8&mysqlEncoding=utf8

user:root

password:123456

如果对应的没变化就不需要改后面提供的框架源码这块都会是错的请谅解

[java]viewplaincopy在CODE上查看代码片派生到我的代码片

#数据库连接配置

db.driverClassName=com.mysql.jdbc.Driver

db.url=VjG9ty54tspjXih4i7GttGhMgOjH9n9fK+PmEKzqTNldvpAhYfSUuRBTf3b++nhyUZERvK3jb0VqFpnhJF0Whf1k7QSvjxxY1FaNlCT+Vz5cwk3kNBUfUHZ5EcLPNLOl

db.user=0q87vZtbVbk=

db.password=XfSWPx0Kqvg=

db.initialSize=2

db.minIdle=2

db.maxActive=10

db.maxWait=6000



#邮件服务器设置

mail.smtp.host=smtp.qiye.163.com

mail.smtp.port=465

mail.smtp.auth=true

mail.smtp.timeout=25000

mail.username=@.com

mail.password=



#Redis缓存配置

redis.minIdle=5

redis.maxIdle=100

redis.maxTotal=300

redis.maxWaitMillis=3000

redis.testOnBorrow=true

redis.host=127.0.0.1

redis.port=6379

redis.password=yxt123

redis.database=1

配置文件到这里都差不多了文件内注解都有应该都能看懂至于框架的详细功能和实现方式就下次有时间在写!

献花(0)
+1
(本文系网络学习天...首藏)