理论学习与实践的差距:框架开源与不可逆的趋势
一、前言
从事Java学习与工作的人都知道,这个行业以开源的形式构建起各种各样的框架,在这些开源框架的基础上,我们以闭源的形式构建我们的项目。因而,今天也开源我自己学习用的SSM框架的基本配置及目录形式。这个框架是学习别人的基础上,经过年月的积累,日渐而成。当然,工作中实践中用到的架构可不是这么简单,但SSM是很多项目的基本架构,也是我们需要去掌握了解的架构。
二、不可逆的趋势
当我们走进Java这个领域的时候,我们都会接触到S2SH框架,甚至到现在还有公司的招聘信息中出现S2SH框架。曾经我也学过Struts2,也用过Struts2,但到了今天,我觉得这个框架可以直接跳过,不需要学习。现在基本上绝大多数的项目都是用SpringMVC作为MVC框架,即使还存在的Struts2项目,也面临淘汰和重构。为什么我们要淘汰Struts2?入门的门槛高,使用起来也臃肿,不方便。相反,SpringMVC框架几天的功夫便可上手,使用起来也方便。
至于现在,依然有公司使用Hibernate框架,这个是根据项目的特点,项目的需求而选择使用的。但相比而言,Mybatis确实存在优势:容易学习,多表查询灵活方便。
在理论学习当中,我们都会以S2SH这一经典框架来学习,然而实际上,正在往SSM框架上迁移。正如10年前,到处可见的XP系统,现在正逐渐被WIN7和WIN10取代,EJB的重量级导致Spring的诞生,然而Spring没有固步自封,开发出SpringBoot框架。SpringBoot也将会取代Spring框架。
Java是一个不断变化的行业,昨天的框架会被今天的框架所替代,今天的框架也会被未来所淘汰。唯一不变的是Java的核心编程思想,唯一不变的是不可逆的趋势。不可能Java7用回Java1,不可能SpringMVC用回Struts2。
三、SSM框架代码
1、所需jar包
2、web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>MyBatisPro05</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><!-- 添加对Spring的支持 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- SpringMVC解决中文乱码问题 --><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- Spring监听器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- SpringMVC配置 --><servlet><servlet-name>springMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springMVC</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping>
</web-app>
3、applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <!-- 自动扫描 --><context:component-scan base-package="com.test.dao" /><context:component-scan base-package="com.test.service" /><!-- 配置数据源 --><bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/db_test"/><property name="username" value="root"/><property name="password" value="123456"/></bean><!-- 配置mybatis的sqlSessionFactory --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><!-- 自动扫描mappers.xml文件 --><property name="mapperLocations" value="classpath:com/test/mappers/*.xml"></property><!-- mybatis配置文件 --><property name="configLocation" value="classpath:mybatis-config.xml"></property></bean><!-- DAO接口所在包名,Spring会自动查找其下的类 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.test.dao" /><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property></bean><!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!-- 配置事务通知属性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <!-- 定义事务传播属性 --> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="new*" propagation="REQUIRED" /> <tx:method name="set*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="change*" propagation="REQUIRED" /> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" propagation="REQUIRED" read-only="false" /> </tx:attributes> </tx:advice> <!-- 配置事务切面 --> <aop:config> <aop:pointcut id="serviceOperation" expression="execution(* com.test.service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" /> </aop:config> </beans>
4、spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <!-- 使用注解的包,包括子集 --><context:component-scan base-package="com.test.controller" /><!-- 支持对象与json的转换。 --><mvc:annotation-driven/> <!-- 视图解析器 --><bean id="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/" /><property name="suffix" value=".jsp"></property></bean><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 上传文件大小上限,单位为字节(10MB) --><property name="maxUploadSize"> <value>10485760</value> </property> <!-- 请求的编码格式,必须和jSP的pageEncoding属性一致,以便正确读取表单的内容,默认为ISO-8859-1 --><property name="defaultEncoding"><value>UTF-8</value></property></bean><!-- 拦截器 --><!-- <mvc:interceptors><bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /><mvc:interceptor><mvc:mapping path="/**" /><mvc:exclude-mapping path="/admin/**" /><bean class="com.test.interceptor.HandlerInterceptor" /></mvc:interceptor></mvc:interceptors> -->
</beans>
5、mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!-- 别名 --><typeAliases><package name="com.test.entity"/></typeAliases>
</configuration>
6、log4j.properties [1]
log4j.rootLogger=info,appender1,appender2log4j.appender.appender1=org.apache.log4j.ConsoleAppender log4j.appender.appender2=org.apache.log4j.FileAppender
log4j.appender.appender2.File=D:/workspace/Test/logFile.txtlog4j.appender.appender1.layout=org.apache.log4j.TTCCLayout
log4j.appender.appender2.layout=org.apache.log4j.TTCCLayout
7、目录结构
四、后记
上面的代码仅仅是SSM框架的架构,在实际开发中,大多数的项目会使用Maven进行项目管理,不需要自己下载jar包。同时框架也会比SSM基本框架负责得多,比如加上Shiro权限框架,在这基础上封装成一个权限系统。每家公司都会有他们自己的一套框架,在原有通用框架之上再进行封装,以提高开发效率。
本文旨在提供一个原生态的SSM学习框架,为之后的本章提供参考,如有错漏之处,恳请各位不吝赐教,交流讨论。
Reference:
[1] 配置Log4j, https://blog.csdn.net/ryelqy/article/details/74999455
理论学习与实践的差距:框架开源与不可逆的趋势相关推荐
- 30名工程师,历时1300天打造,又一“国产”AI框架开源了
作者 | Just 出品 | CSDN(CSDNnews) "我发现,软件研发总会延期."一流科技CEO袁进辉说. 按照他的预期,深度学习框架OneFlow做两年就能开源给开发者检 ...
- android colorstatelist_B站Android多主题框架开源:MagicaSakura
最近不少同学在后台催更,还有朋友开始问我是不是出啥事了- -!,是得出来解释下,其实就是最近重心没有放在公众号这块,至于具体缘由就不说啦,感觉各种借口都要被我用完了,你们就当我懒癌复发吧.讲真,真心要 ...
- 各种Android UI开源框架 开源库
各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...
- 阿里深度学习框架开源了!无缝对接TensorFlow、PyTorch
阿里巴巴内部透露将开源内部深度学习框架 X-DeepLearning的计划,这是业界首个面向广告.推荐.搜索等高维稀疏数据场景的深度学习开源框架,可以与TensorFlow.PyTorch 和 MXN ...
- 恭喜龙蜥获得中国开源云联盟2022年度中国“最佳开源实践案例”和“杰出开源贡献者”奖项
近日,由工信部中国电子技术标准化研究院主办的 2022 木兰峰会在北京圆满举办,峰会上正式公布了中国开源云联盟(China Open Source Cloud League,简称"COSCL ...
- Cola机器人PC框架开源
介绍: Cola机器人PC框架开源 网盘下载地址: http://kekewl.org/9vtcns01H5R 图片:
- 【带你看看开源圈的新趋势】GITHUB OCTOVERSE 2022 详细解读
一.写在前面 GITHUB OCTOVERSE 是由世界上最大的代码托管平台 GITHUB 发起的开源趋势调查,旨在探索开源的新趋势,以及对于开发者和软件公司的影响.通过分析 GITHUB OCTOV ...
- 开放原子开源基金会副秘书长刘京娟:中国开源发展现状及趋势思考
"软件定义未来的世界,开源决定软件的未来",开源已成为全球软件技术和产业创新的主导模式.开源基金会作为开源项目的重要推动者与组织者,在开源生态中发挥着重要作用. 2022年7月21 ...
- 13 大论坛同开播!数百专家带你从机器学习技术与工程实践,聊到开源生态 | AI ProCon 2020...
2020 年 7 月 4 日,由 CSDN 主办的第三届 AI开发者大会(AI ProCon 2020)在线上进行到了第二天的议程.作为"百万人学AI"的阶段性成果展示,AI Pr ...
最新文章
- python私有属性和property装饰器_python – 在使用@property装饰器时在属性的s...
- [NOI2012(bzoj2879)(vijos1726)]美食节 (费用流)
- 作者:景志刚(1977-),男,现就职于中国人民银行征信中心数据部,主要研究方向为数据挖掘。...
- amp mysql升级_【简单的案例分享,停机10分钟】10204升级CRSamp;amp;DB的PSU至1
- Atitit.编程语言原理---方法重载的实现与设计 调用方法的原理
- 【Oracle】常用SQL
- 使用Telnet 在DS300上配置阵列
- 3dmax材质丢失插件_3dmax找回材质插件怎么用
- 使用HDMI转DVI线组双屏
- Java工具类 BeanUtils库介绍以及对象拷贝
- jquery的odd和even
- 阿里云自建k8s存储插件csi安装使用
- 物联网新零售项目 新零售制胜之道
- (java)Climbing Stairs
- Spring Boot普通参数与基本注解
- 去掉首尾字符java_Java去除字符串首尾特定字符
- #触摸一体机##五指息屏#
- dirname 使用总结
- 北京科技大学计算机保研,北京科技大学考研/保研怎么样?这些数据必须知道!...
- Android与Linux分道扬镳
热门文章
- 大一新手多多包涵。日常小程序练习
- Database数据库的分库分表,表映射,切换表,使用到了IModelCacheKeyFactory 代码如下:
- 数据结构---------层次建树(完全二叉树)
- 军犬舆情每日热点:广西自治区成立60周年;首批5G手机价格8000元
- Android电量监控
- 如何清理卸下应用的残余文件_Win10系统卸载软件程序及清除残留文件的方法有哪些?...
- 新能源汽车,疯狂收割 IT 男
- 酷播项目专辑(整理好播放器的一些范例)
- 华为发布新一代全屋智能解决方案,80平39999元起。你心动了吗?
- buu Reverse学习记录(19) [GWCTF 2019]pyre