温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springmvc+mybatis +Jeesz 分布式架构

发布时间:2020-08-09 17:52:27 来源:ITPUB博客 阅读:138 作者:橙色的雨 栏目:编程语言

spring mvc

Spring框架(框架即:编程注解+xml配置的方式)MVC是Spring框架的一大特征,Spring框架有三大特征(IOC(依赖注入),AOP(面向切面),MVC(建模M-视图V-控制器C)。框架一般用于团队开发,使用分层的方式使每个人完成不同的模块,然后再组合在一起,使完成项目。

以下是Spring mvc具有的能加速开发的功能列表:

  • Spring mvc中提供了一个DispatchServlet,无需额外开发
  • Spring mvc中使用基于xml的配置文件,可以编辑,而无需重新编译应用程序
  • Spring mvc实例化控制器,并根据用户输入来构造Bean。
  • Spring mvc可以自动绑定用户输入,并正确的转换数据类型。例如,Spring mvc能自动解析字符串,并设置float或decimal类型的属性.
  • Spring mvc可以校验用户输入,若校验不通过,则重定向回输入表单。输入校验是可选的,支持编程方式以及声明。关于这一点,Spring mvc内置了常见的校验器
  • Spring mvc是Spring框架的一部分,可以利用Spring提供的其他能力。
  • Spring mvc支持国际化和本地化。支持根据用户区域显示多国语言
  • Spring mvc支持多种视图技术。最常见的JSP技术以及其他技术包括Velocity和FreeMarker.

Spring与MyBatis结合,主要是由Spring管理数据库访问组件Dao,数据库访问组件主要是基于MyBatis实现,在Spring环境中使用MyBatis实现数据库访问组件过程是:首先需要引入一个Spring和MyBatis整合的开发包 mybatis-spring-1.2.2.jar。在Spring配置中定义SqlSessionFactoryBean,等价于SqlSessionFactory放入Spring容器管理。(不需要开发者利用手工创建SqlSessionFactory对象,需要开发者定义式注入连接信息和SQL定义的XML信息)在Spring配置中定义MapperFactoryBean,可以根据指定的Mapper接口生成一个Mapper实现类接口。需引入引入开发包:spring ioc,spring aop,dbcp,mybatis,驱动,mybatis-spring.jar。添加Spring框架的配置文件主要有applicationContext.xml,根据user表编写实体类User,编写UserMapper.xml(定义SQL语句),并且编写UserMapper接口(与UserMapper.xml映射),在applicationContext.xml中配置组件SqlSessionFactoryBean,Mapper FactoryBean。最后测试MapperFactoryBean生成的UserMapperDao实例。

  MyBatis的两个特点:

  1.MyBatis采用SQL与Entity映射,对JDBC封装程度较轻

  2.MyBatis自己写SQL,更具有灵活性

  下面给大家介绍下JEESZ的简介,springmvc,springmybatis  的整合。

         Jeesz是一个分布式的框架,提供项目模块化、服务化、热插拔的思想,高度封装安全性的Java EE快速开发平台。

        Jeesz本身集成Dubbo服务管控、Zookeeper注册中心、Redis分布式缓存技术、FastDFS分布式文件系统、ActiveMQ异步消息中间件、Nginx负载均衡等分布式技术

        使用Maven做项目管理,项目模块化,提高项目的易开发性、扩展性

        以Spring Framework为核心容器,Spring MVC为模型视图控制器,MyBatis为数据访问层, Apache Shiro为权限授权层,Ehcahe对常用数据进行缓存,Activit为工作流引擎等。

        前端集成Bootstrap4 metronic框架,UI响应式、扁平化布局,适应所有PC、Pad、Anroid、iOS 移动设备等。

        Jeesz主要定位于互联网企业架构,已内置企业信息化系统的基础功能和高效的代码生成工具,包括:系统权限组件、数据权限组件、数据字典组件、核心工具 组件、视图操作组件、工作流组件、代码生成等。采用分层设计、双重验证、提交数据安全编码、密码加密、访问验证、数据权限验证。

        Jeesz目前包括以下模块项目,后台系统管理系统,RestFul独立服务系统、Scheduler定时调度系统、内容管理(CMS)系统、在线办公(OA)系统、我的待办(Task服务)、我的收藏(Bookmark服务)。

        后台管理系统包括企业组织架构(用户管理、机构管理、区域管理)、菜单管理、角色权限管理、字典管理等功能;

        RestFul独立提供标准Rest服务API,您可以快速实现自己的业务,提供需要的服务;

        Quartz定时调度系统可以动态配置您的任务规则等;

愿意了解框架技术或者源码的朋友直接加QQ(2042849237

        内容管理(CMS)系统,包括内容管理,栏目管理、站点管理、公共留言、文件管理、前端网站展示等功能;

        在线办公(OA)系统,主要提供简单的流程实例。

        Jeesz提供了常用工具进行封装,包括日志工具、缓存工具、服务器端验证、数据字典、当前组织机构数据(用户、机构、区域)以及其它常用小工具等。另外 还提供一个强大的在线 代码生成 工具,此工具提供简单的单表、一对多、树结构功能的生成,如果对外观要求不是很高,生成的功能就可以用了。使用了Jeesz基础框架,可以提高快速开发效 率。

整合SpringMVC
springMybatis-servlet.xml:
  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3.        xmlns:context="http://www.springframework.org/schema/context"  
  4.        xmlns:mvc="http://www.springframework.org/schema/mvc"  
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  6.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  
  7.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">  
  8.       
  9.         <!-- 启用spring mvc 注解-->  
  10.     <mvc:annotation-driven>   
  11.     </mvc:annotation-driven>  
  12.       
  13.     <!-- 自动扫描的包名 ,使Spring支持自动检测组件,如注解的Controller-->  
  14.     <context:component-scan base-package="com.alibaba.controller" />  
  15.     <context:component-scan base-package="com.alibaba.service"/>  
  16.       
  17.       
  18.     <!-- 视图解析器:定义跳转的文件的前后缀 -->    
  19.     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">    
  20.         <property name="prefix" value="/WEB-INF/jsp/" />    
  21.         <property name="suffix" value=".jsp" />  <!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑  -->  
  22.     </bean>    
  23.   
  24.     <!--配置拦截器, 多个拦截器,顺序执行 -->   
  25.     <mvc:interceptors>    
  26.         <mvc:interceptor>    
  27.             <!-- 匹配的是url路径  -->  
  28.             <mvc:mapping path="/" />  
  29.             <mvc:mapping path="/user/**" />  
  30.             <mvc:mapping path="/test/**" />  
  31.               
  32.             <bean class="com.alibaba.interceptor.CommonInterceptor"></bean>    
  33.         </mvc:interceptor>  
  34.         <!-- 当设置多个拦截器时,先按顺序调用preHandle方法,然后逆序调用每个拦截器的postHandle和afterCompletion方法 -->  
  35.     </mvc:interceptors>  
  36.         
  37. </beans>     


2.整合Mybatis

spring-dao.xml:
  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3.        xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"  
  4.        xmlns:context="http://www.springframework.org/schema/context"  
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  6.        http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd  
  7.        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
  8.       
  9.     <!-- 该包下的类支持注解,表示会被当作{@code mybatis mapper}处理 配置了之后表示可以自动引入mapper类-->  
  10.     <mybatis:scan base-package="com.alibaba.dao"/>  
  11.     <!--引入属性文件 -->  
  12.     <context:property-placeholder location="classpath:configuration.properties"/>  
  13.       
  14.     <!--数据库连接-->  
  15.     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">   
  16.         <property name="url" value="${jdbc.url}" />  
  17.         <property name="username" value="${jdbc.username}"/>  
  18.         <property name="password" value="${jdbc.password}"/>  
  19.         <!-- 配置初始化大小、最小、最大 -->  
  20.         <property name="initialSize"><value>1</value></property>  
  21.         <property name="maxActive"><value>5</value></property>  
  22.         <property name="minIdle"><value>1</value></property>  
  23.         <!-- 配置获取连接等待超时的时间 -->  
  24.         <property name="maxWait"><value>60000</value></property>  
  25.         <!-- 配置监控统计拦截的filters -->  
  26.         <property name="filters"><value>stat</value></property>  
  27.         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->  
  28.         <property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>  
  29.         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->  
  30.         <property name="minEvictableIdleTimeMillis"><value>300000</value></property>  
  31.         <!--  
  32.         <property name="validationQuery"><value>SELECT 'x'</value></property>  
  33.         <property name="testWhileIdle"><value>true</value></property>  
  34.         <property name="testOnBorrow"><value>false</value></property>  
  35.         <property name="testOnReturn"><value>false</value></property>  
  36.         <property name="poolPreparedStatements"><value>true</value></property>  
  37.         <property name="maxOpenPreparedStatements"><value>20</value></property>  
  38.          -->  
  39.     </bean>  
  40.       
  41.     <!-- mybatis配置 -->  
  42.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  43.         <property name="dataSource" ref="dataSource" />  
  44.     </bean>   
  45. </beans>     
springmvc+mybatis +Jeesz 分布式架构

想了解更多详细请点击源码地址获取:mingli.com

有兴趣的朋友们可以前往球球哦~一起分享学习技术:2042849237

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI