SpringMvc+Mybatis+Redis框架.docx
- 文档编号:3507661
- 上传时间:2022-11-23
- 格式:DOCX
- 页数:24
- 大小:153.66KB
SpringMvc+Mybatis+Redis框架.docx
《SpringMvc+Mybatis+Redis框架.docx》由会员分享,可在线阅读,更多相关《SpringMvc+Mybatis+Redis框架.docx(24页珍藏版)》请在冰豆网上搜索。
SpringMvc+Mybatis+Redis框架
SpringMvc+Mybatis+Redis框架
框架运行环境:
Maven版本:
3.3.9
Eclipse版本:
MARS.2
JDK版本:
1.8
Tomcat版本:
8.0.36
框架结构:
框架全采用maven管理所以源码只有180KB左右要是不会Maven就请自行补习
annotation:
自定义注解实现的类似于shiro的权限但是比较简单不喜勿喷没shiro强大但是比他简单然后自己结合RBAC+Redis+Intercept技术实现的,对于自己目前遇到的权限问题我用这个也完全够用了。
至于为什么没用shiro并不是shiro不强大只是不太喜欢那么复杂的用法(虽然已经很简单了)我是懒得出奇的人不过还是建议大家多去学习shiro这个权限框架毕竟连spring都推荐使用ShiroRBAC是一个数据库的设计模型简单理解为:
用户-角色-权限-资源
entity:
实体类的父类很简单自己看源码就行
log4j:
这里重写了log4j的SMTPAppender这个类首先说说这个类是干嘛的他是用来发送邮件的当报错时邮件通知管理员,具体的请参考我的另一篇博客,上面有详细介绍点击打开链接
mapper:
所有mapper的父类默认提供了几个常用的方法
message:
提示语相关的东西都不知道咋描述就是为了代码中不允许有一个中文和硬编码的存在当然自己也可以改改实现国际化
result:
针对返回结果的格式的统一封装题外话:
这个框架完全是为了提供接口而生所以很多什么页面跳转什么滴都没做只做了返回json这块连异常都封装成JSon了所以有其他要求的只能自己修改修改了
tools:
看名字就知道一些常用的工具类有什么身份证、经纬度、日期计算、DES和RSA加密、MD5之类的东西具体请看代码类注解我觉得我注解已经很多了
redis:
这里重写了spring-data-redis里面的RedisCache、RedisCachemanager两个类和封装了一些其他的类目的就是为了实现redis的自动续期和单用户登录功能(一个用户同时只能在一个地方登录)如果需要实现不同平台的单用户登录需要自己小改一下在缓存中多加个平台标识就行了
butler:
这是web项目名字不必纠结介绍下包的作用
org.service:
系统的一些服务类这里只有定时任务(SpringTask)和SpringMail邮件推送服务
org.system:
这个看里面的包就知道干嘛用的了就说说exception和interception这两个
org.system.exception:
全局异常处理这里把所有的程序异常捕捉并用JSON返回,以免其他客户端在服务器报错时出现一些数据无法解析造成的其他问题。
至于项目的异常自己也做了配置和封装,在报错的时候可以异步发送邮件给管理员,具体实现请继续往下看
框架的大致结构就介绍到这里下面说一下配置的xml有人说多其实还还好,不喜欢多的可以合一下,两个就能解决了,我分开是为了更明显的区分
web.xml
[html]viewplaincopy在CODE上查看代码片派生到我的代码片
xmlversion="1.0"encoding="UTF-8"?
>
xsi="http: //www.w3.org/2001/XMLSchema-instance" 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"> --声明Spring配置文件所在目录--> classpath*: applicationContext.xml, classpath*: spring-*.xml --声明IntrospectorCleanupListener监听器防止反复加载对象造成内存泄漏--> --声明ContextLoaderListener监听器自动装配Spring配置文件信息--> --全局UTF-8编码过滤器--> --配置Spring控制器--> spring-mvc.xml --HttpPutFormContentFilter使put方法是也可以获取表单内的参数这里我有特殊需求标准的Rest可以去掉--> 接下来是Spring的主配置文件applicationContext.xml [html]viewplaincopy在CODE上查看代码片派生到我的代码片 xmlversion="1.0"encoding="utf-8"? > //www.springframework.org/schema/beans" 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"> --配置需要交给spring扫描管理的包,一般是包括整个项目的java文件的父包(由context提供)--> component-scanbase-package="org.system,org.service.task"/> --属性文件读入,用于加密数据库配置文件--> conf.properties --配置需要交给spring扫描管理的文件,一般是项目的配置文件(由context提供)--> property-placeholderlocation="classpath: conf.properties"/> --配置数据源--> --基本配置--> --初始化时建立物理连接的个数--> --最小连接池数--> --最大连接池数量--> --配置获取连接等待超时的时间--> --配置sqlSessionFactory(由mybatis-spring.jar提供支持)--> --配置数据源--> --配置mybatis的默认选项--> --配置拦截器用于Mybatis分页和总数查询,只实现Mysql其他的可以参照--> --mybatis默认选项配置这里是因为我返回全是用Map所以如果数据库有字段为空就会使这个属性不显示为了解决这个问题才需要配置这个--> --Mybatis分页拦截器--> --Mapper接口所在包名,Spring会自动查找其下的Mapper--> --支持注解事务模式--> annotation-driventransaction-manager="transactionManager"proxy-target-class="true"/> --事务管理--> --配置声明式事务--> adviceid="txAdvice"transaction-manager="transactionManager"> attributes> methodname="insert*"propagation="REQUIRED"read-only="false"/> methodname="delete*"propagation="REQUIRED"read-only="false"/> methodname="update*"propagation="REQUIRED"read-only="false"/> methodname="get*"propagation="SUPPORTS"/> attributes> advice> --配置该声明式事务规则用于的切入点步骤: 1.配置切入点2.应用该声明式事务规则--> configproxy-target-class="true"expose-proxy="true"> --配置切入点--> pointcutid="transaction_pointcut"expression="execution(*org.system.service.impl..*.*(..))"/> --应用该声明式事务规则--> advisoradvice-ref="txAdvice"pointcut-ref="transaction_pointcut"/> config> --异常拦截器--> --Spring上下文工具类--> 这里说一说有个数据库加密的东西在这里 [html]viewplaincopy在CODE上查看代码片派生到我的代码片 --属性文件读入,用于加密数据库配置文件--> conf.properties 意思就是用DBConfigurer这个类来解密conf.properties这个文件内的几个配置就是采用了DES加密解密主要为了防止配置文件泄露数据库的信息暴露如果不用直接注释掉就可以使用明文了稍后会把properties相关文件贴出来 接下来是spring-mvc.xml [html]viewplaincopy在CODE上查看代码片派生到我的代码片 xmlversion="1.0"encoding="UTF-8"? > //www.springframework.org/schema/beans" 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"> --扫描要自动管理的包--> component-scanbase-package="org.system.controller.impl"/> --静态资源文件路径设置--> resourceslocation="/api/"mapping="/api/**"/> --对模型视图名称的解析,在请求时模型视图名称添加前后缀系统内没有涉及到页面跳转所以基本无用-->
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SpringMvc Mybatis Redis 框架