显示层(handler/controller):

  request请求到springmvc的前端控制器,从处理器映射器找相应的handler(用@RequestMapping("  ")标注,映射成功后,由Springmvc生成一个handler对象,该对象中有一个方法,即映射成功的该方法),由相应的处理器适配器去执行该handler,handler中调用的是业务控制层(service)的方法接口。然后返回jsp地址的字符串或有地址和请求参数的ModelAndView对象(其中装载着参数如name,id,和目标地址即相应的显示页面如jsp,看了部分源码,是用Map存储,然后放到request对象中)到前端控制器,然后前端控制器把ModelAndView传给视图解析器,加上解析器中设置的jsp地址的前缀和后缀,然后把视图返回给前端控制器,再进行视图的渲染(好像就是把map中数据填充的request对象中),返回给客户端。

业务控制层(service):

  一个service接口,还有其相应的实现类serviceImpl,这样做可以使业务控制层的开发和显示层的开发并行进行,因为只要给显示层一个service的接口即可。service层的实现类中用Spring的IOC(Autowired注解)自动注入了一个或多个mapper对象,即该对象是调用sqlSessionFactory的getSession的getBean方法获得的。然后再调用mapper对象的相应方法,需要的时候还应该加入适当的控制流程(比如BeanUtils.copyProperties()方法进行属性的拷贝或业务的校验)。

持久层(dao/mapper):

  用逆向工程生成了相应的mapper.java即相应的mapper.xml,还有和数据库表对应的pojo,这些可以实现比较简单的单表查询。

  如果有多表关联的查询,则需要自定义mapper,因为返回结果包括多个pojo中的属性,不建议直接在pojo中添加相应属性,而应该写一个继承某个pojo类的子类,然后在该子类中添加所需的其他pojo中的属性,这样返回类型即为该子类。其中查询的参数为QueryVo类,其中组合了该上述子类和其他子类的对象,需要什么参数就往里写什么对象。

applicationContext-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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!-- 开启注解. 扫描 -->
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.***"></context:component-scan> <!-- 过滤掉js, jpg, png, css, 静态文件 -->
<mvc:default-servlet-handler/> <!-- 开启mvc
<mvc:annotation-driven />
--> <!-- 第一步: 创建自定义日期转换规则 -->
<bean id="dateConvert" class="com.***.utils.DateConvert"/> <!-- 第二步: 创建convertion-Service ,并注入dateConvert-->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<ref bean="dateConvert"/>
</set>
</property>
</bean> <!-- 第三步:注册处理器映射器/处理器适配器 ,添加conversion-service属性-->
<mvc:annotation-driven conversion-service="conversionService" /> <!--
开启mvc
<mvc:annotation-driven />
<bean id="inter" class="com.***.inter.LoginInter"></bean>
--> <!--
拦截器配置
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>//拦截所有
<ref bean="inter"/>
</mvc:interceptor>
</mvc:interceptors>
--> <!-- 地址解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean> </beans>

  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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <!-- @Component, @Repository, @Service, @Controller, @Autowired, @Resources -->
<!-- 用注解进行开发 -->
<context:annotation-config></context:annotation-config>
<!-- 注解扫描包 -->
<context:component-scan base-package="com.***">
<!-- 这里不加载Controller的bean -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <!-- 1. 数据源 -->
<!-- 读取db.properties文件. 读取到数据库信息 -->
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean> <!-- 2. 创建sqlSessionFactory ==> mybatis核心配置文件的读取 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean> <!-- 3.扫描mybatis的mapper接口路径 -->
<!-- 这个bean可以把我们的mapper接口直接扫描到. 直接把接口扫描完. 注册到spring的bean中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<!-- 会在提供的base包下寻找interface .根据interface的名字. 将首字母小写生成这个接口所对应的bean -->
<property name="basePackage" value="com.***.mapper"></property>
</bean> <!-- 4.事务处理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <tx:advice id="txManager" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="search*" read-only="true"/>
<tx:method name="select*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*" isolation="DEFAULT" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut expression="execution(* com.***.*.*.*.*(..))" id="cut"/>
<aop:advisor advice-ref="txManager" pointcut-ref="cut"/>
</aop:config> <!-- 用注解处理事务
<tx:annotation-driven transaction-manager="transactionManager"/>
-->
</beans>

  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><!-- mybatis的核心配置 -->
<!-- mybatis的运行配置 -->
<settings>
<!-- 开启二级缓存 -->
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<!-- 如果这个属性是true,那么你的类中, 任何一个方法被执行.都要去加载属性,
这个时候懒加载是没有效果的.
-->
<setting name="aggressiveLazyLoading" value="false"/>
</settings> </configuration>

  web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 读取除了mvc外的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <!-- 整个web容器的动向由这个监听器进行监听. 这个监听器可以监听项目的启动. 从而直接加载核心配置文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>characterEncodingFilter</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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 自定义过滤器 --> <filter> <filter-name>LoginFilter</filter-name>
<filter-class>com.***.filter.LoginFilter</filter-class> </filter> <filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/*</url-pattern> </filter-mapping> <servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 给出spring的路径 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup><!-- 当web容器加载的时候, 初始化spring -->
</servlet> <servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern><!-- 所有 -->
</servlet-mapping> <listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener> </web-app>

  

SSM的XML和WEB.XML的配置的更多相关文章

  1. Eclispe创建maven工程缺失web.xml报web.xml is missing and <failOnMissingWebXml> is set to true的错误

    Eclispe创建maven工程缺失web.xml报web.xml is missing and <failOnMissingWebXml> is set to true的错误,一看,还缺 ...

  2. SSM搭配中的web.xml的配置信息

    最近一段时间在自己学着搭建SSM框架的项目,其实这个项目自由自己不断尝试,不断失败,才能印象更深刻. 下面就说一下在项目中的web.xml的相关配置信息: <?xml version=" ...

  3. SpringMVC 常用applicationContext.xml、web.xml、servlet-mvc.xml简单配置

    在进行学习配置文件之前,为了加深对框架的认识,简单的做了SSM框架的简单实验.然后画出listAll查询方法的整个过程的思维导图. 整个过程中的web.xml.SpringMVC.xml.applic ...

  4. applicationContext.xml和web.xml的一些配置

    applicationContext.xml <!-- test环境 --> <beans profile="test"> <context:prop ...

  5. 一文懂SSM项目中的web.xml常用配置项

    做web后端工程师,逃不过的web.xml,我们都知道配置这个文件是日常工作了,那么我们来把一些必须知道知识点梳理下. 我们把web项目启动的时候,首先加载的就是web.xml这个文件,只有这个文件所 ...

  6. springmvc.xml,context.xml和web.xml

    1:springmvc.xml配置要点 一般它主要配置Controller的组件扫描器和视图解析器 下为:springmvc.xml文件 <?xml version="1.0" ...

  7. pom.xml出现web.xml is missing and <failOnMissingWebXml> is set to true解决方案

    提示信息应该能看懂.也就是缺少了web.xml文件,<failOnMissingWebXml>被设置成true了. 搜索了一下,Stack Overflow上的答案解决了问题,分享一下. ...

  8. 每天学会一点点(spring-mvc.xml与web.xml配置文件)

    1.spring-mvc.xml中拦截器的使用 首先在springMVC.xml配置如下代码: <!-- 拦截器 --> <mvc:interceptors> <bean ...

  9. pom.xml中web.xml is missing and <failOnMissingWebXml> is set to true错误的解决

    .personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...

随机推荐

  1. swift学习之UIButton

    // //  ViewController.swift //  button // //  Created by su on 15/12/7. //  Copyright © 2015年 tian. ...

  2. jmeter 性能分析 (一点点加)

    1.聚合报告 我们可以看到,通过这份报告我们就可以得到通常意义上性能测试所最关心的几个结果了. Samples -- 本次场景中一共完成了多少个Transaction Average -- 平均响应时 ...

  3. Codeforces 768A Oath of the Night's Watch 2017-02-21 22:13 39人阅读 评论(0) 收藏

    A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...

  4. SQL描述(2)

    很久之前就想写出来,就是因为自己太懒,憋了怎么久.本文关于使用ORACLE分析函数对一些经济指标进行计算.表indi_value有3个关键的字段:indi_date,indi_value,indi_i ...

  5. 18-11-2 Scrum Meeting 5

    1. 会议照片 2. 工作记录 - 昨天完成工作 1 把数据导入数据库 2 中译英选择题和英译中选择题的查询接口 - 今日计划工作 1 配置页面 2 实现中译英选择题和英译中选择题的查询接口 3 整理 ...

  6. jsp+mysql的字符过滤器

    jsp+mysql项目里面,在和数据库交互的时候,总是出现乱码.这都是老生常谈的事情了. 之前在那里放了一放,今天觉得还是尽早解决.用了一个过滤器. 代码: package wang.util; im ...

  7. Replication--复制相关的作业

    复制使用下列作业来执行计划维护和按需维护 作业名称 说明 默认调度 代理历史记录清除:分发 从分发数据库中删除复制代理历史记录. 每十分钟运行一次 分发清除:分发 从分发数据库中删除复制的事务. 停用 ...

  8. linux查看占用内存多的进程

    update一个简单的方法 ps aux | sort -k4nr | head -10 ps -e  -o "%C  : %p : %z : %a"|sort -k5 -nr|h ...

  9. 打造一个简单实用的的TXT文本操作及日志框架

    首先先介绍一下这个项目,该项目实现了文本写入及读取,日志写入指定文件夹或默认文件夹,日志数量控制,单个日志大小控制,通过约定的参数让用户可以用更少的代码解决问题. 1.读取文本文件方法 使用:JIYU ...

  10. MVC中获取所有按钮,并绑定事件!

    <script> var btns = $('[id=addbtn]'); //不能直接使用#ID来获取,必须用[] //循环遍历所有的按钮,一个一个添加事件绑定   for (var i ...