web.xml (tomcat启动时读取的配置文件)

首页配置
<welcome-file-list>:index.jsp

servlet配置(<servlet>和<servletmapping>配对出现)
<servlet>
servlet名称
servlet类包路径
servlet初始化参数
参数key:contextConfigLocation
参数值:classpath:spring-servlet.xml,指定servlet初始化的配置文件
指定tomcat容器启动时是否实例化本servlet并调用init方法
<servletmapping>
servlet名称
servlet的url匹配

容器参数配置<context-param>
参数key:contextConfigLocation
参数值:classpath:applicationContext.xml,指定容器参数的配置文件

spring框架监听器配置<listener>
org.springframework.web.context.ContextLoaderListener

////////////////////////////////////////////////////////////////////////////////////////////////////

spring-servlet.xml (指定servlet初始化的配置文件)
启动注解驱动
mvc:annotation-driven
启动包扫描
context:component-scan
添加对模型视图名称的解析
viewClass、prefix、suffix

////////////////////////////////////////////////////////////////////////////////////////////////////

applicationContext.xml (指定容器参数的配置文件)

上下文注解配置
context:annotation-config
启动包扫描
context:component-scan
导入mybatis的配置文件
<import>:spring-mybatis.xml

////////////////////////////////////////////////////////////////////////////////////////////////////

spring-mybatis.xml (数据库配置)

指定配置业务sql的配置文件
classpath:mapper/*.xml
配置事物管理
org.springframework.jdbc.datasource.DataSourceTransactionManager

web.xml

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<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_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<!-- Spring MVC配置 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--Spring-servlet.xml config-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<!-- load-on-startup元素标记容器是否在启动的时候就加载这个servlet(实例化并调用其init()方法) -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <!--spring listener config-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

  

index.jsp

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

  

spring-servlet.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <!-- 启动注解驱动的Spring MVC功能,注册请求url和注解POJO类方法的映射-->
<mvc:annotation-driven > </mvc:annotation-driven> <!-- 启动包扫描功能,以便注册带有@Controllers、@service、@repository、@Component等注解的类成为spring的bean -->
<context:component-scan base-package="Controllers" />
<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/"/> <!-- 前缀 -->
<property name="suffix" value=".jsp"/> <!-- 后缀 -->
</bean>
<!-- 访问静态文件(jpg,js,css)的方法 -->
<!--<mvc:resources location="/files/" mapping="/files/**" />-->
<!--<mvc:resources location="/scripts/" mapping="/scripts/**" />-->
<!--<mvc:resources location="/styles/" mapping="/styles/**" />-->
<!--<mvc:resources location="/Views/" mapping="/Views/**" />-->
</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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config />
<!-- 配置component所在的包,自动加载需要管理的Bean -->
<context:component-scan base-package="Service,Dao" />
<import resource="spring-mybatis.xml" />
</beans>

  

spring-mybatis.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="configProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean> <!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>
<property name="acquireRetryAttempts" value="${c3p0.acquireRetryAttempts}"/>
<property name="acquireRetryDelay" value="${c3p0.acquireRetryDelay}"/>
<property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}"/>
<property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"/>
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"/>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"/>
<property name="testConnectionOnCheckin" value="${c3p0.testConnectionOnCheckin}"/>
<property name="maxStatements" value="${c3p0.maxStatements}"/>
<property name="maxStatementsPerConnection" value="${c3p0.maxStatementsPerConnection}"/>
<property name="unreturnedConnectionTimeout" value="${c3p0.unreturnedConnectionTimeout}"/>
</bean> <!-- 配置mybatisSqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!-- 配置mybatis mapper接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="Dao"/>
<!--<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>-->
</bean> <!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> </beans>

  

StudentMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Dao.StudentMapper">
<resultMap id="BaseResultMap" type="Entity.Student">
<id column="Uid" jdbcType="BINARY" property="uid" />
<result column="Name" jdbcType="VARCHAR" property="name" />
<result column="Age" jdbcType="INTEGER" property="age" />
<result column="ClassId" jdbcType="INTEGER" property="classid" />
</resultMap>
<sql id="Base_Column_List">
Uid, Name, Age, ClassId
</sql>
<select id="selectByPrimaryKey" parameterType="byte[]" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from student
where Uid = #{uid,jdbcType=BINARY}
</select>
<select id="selectByCondition" parameterType="Entity.Student" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
from student
<where>
1=1
<if test="uid != null">
and Uid=#{uid,jdbcType=BINARY}
</if>
<if test="name != null">
and Name=#{name,jdbcType=VARCHAR}
</if>
<if test="age != null">
and Age=#{age,jdbcType=INTEGER}
</if>
<if test="classid != null">
and ClassId=#{classid,jdbcType=INTEGER}
</if>
</where>
</select>
<delete id="deleteByPrimaryKey" parameterType="byte[]">
delete from student
where Uid = #{uid,jdbcType=BINARY}
</delete>
<insert id="insert" parameterType="Entity.Student">
insert into student (Uid, Name, Age,
ClassId)
values (#{uid,jdbcType=BINARY}, #{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER},
#{classid,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="Entity.Student">
insert into student
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uid != null">
Uid,
</if>
<if test="name != null">
Name,
</if>
<if test="age != null">
Age,
</if>
<if test="classid != null">
ClassId,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="uid != null">
#{uid,jdbcType=BINARY},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="age != null">
#{age,jdbcType=INTEGER},
</if>
<if test="classid != null">
#{classid,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="Entity.Student">
update student
<set>
<if test="name != null">
Name = #{name,jdbcType=VARCHAR},
</if>
<if test="age != null">
Age = #{age,jdbcType=INTEGER},
</if>
<if test="classid != null">
ClassId = #{classid,jdbcType=INTEGER},
</if>
</set>
where Uid = #{uid,jdbcType=BINARY}
</update>
<update id="updateByPrimaryKey" parameterType="Entity.Student">
update student
set Name = #{name,jdbcType=VARCHAR},
Age = #{age,jdbcType=INTEGER},
ClassId = #{classid,jdbcType=INTEGER}
where Uid = #{uid,jdbcType=BINARY}
</update>
</mapper>

  

web.xml 简记的更多相关文章

  1. 如何用Java类配置Spring MVC(不通过web.xml和XML方式)

    DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置方式, XML看起来太累, 冗长繁琐. 还好借助于Servl ...

  2. web.xml中welcome-file-list的作用

    今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...

  3. web.xml中load-on-startup的作用

    如下一段配置,熟悉DWR的再熟悉不过了:<servlet>   <servlet-name>dwr-invoker</servlet-name>   <ser ...

  4. springmvc配置文件web.xml详解各方总结(转载)

    Spring分为多个文件进行分别的配置,其中在servlet-name中如果没有指定init-param属性,那么系统自动寻找的spring配置文件为[servlet-name]-servlet.xm ...

  5. Java web.xml 配置详解

    在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是 ...

  6. web.xml中url-pattern的用法

    目录结构: // contents structure [-] url-pattern的三种写法 servlet匹配原则 filter匹配原则 语法错误的后果 参考文章 一.url-pattern的三 ...

  7. MAC OS X El CAPITAN 搭建SPRING MVC (1)- 目录、包名、创建web.xml

    一. 下载STS(Spring Tool Suite) 官方地址:http://spring.io/tools/sts 下载spring tool suite for mac 最新版本.这个IDE是很 ...

  8. Web.xml配置详解之context-param

    <context-param> <param-name></param-name> <param-value>></param-value& ...

  9. javaWeb项目中Web.xml的基本配置

    这个地址写的非常好 ,欢迎大家访问 Å:http://www.cnblogs.com/hxsyl/p/3435412.html 一.理论准备 先说下我记得xml规则,必须有且只有一个根节点,大小写敏感 ...

随机推荐

  1. ubuntu下面配置apache

    1.在这个目录下面修改这个文件 把那个注释了 2.在这个目录下面修改这个文件 把这个改为index的目录

  2. [2019.03.22] Linux 学习心得(1)

    本文关键词:shell 判断.grep正则表达式使用和贪婪匹配理解 1. if [ $a -le $b ], 一开始自学的时候我以为 [ ... ] 就是普通的,语法规定的结构,结果其实人家是&quo ...

  3. vscode的插件收集

    转:https://zhuanlan.zhihu.com/p/27905838 转:https://segmentfault.com/a/1190000006697219

  4. 一本通网站 1378:最短路径(shopth)

    [题目描述] 给出一个有向图G=(V, E),和一个源点v0∈V,请写一个程序输出v0和图G中其它顶点的最短路径.只要所有的有向环权值和都是正的,我们就允许图的边有负值.顶点的标号从1到n(n为图G的 ...

  5. Android Intent 传递数据注意事项

    不要通过 Intent 在 Android 基础组件之间传递大数据(binder transaction缓存为 1MB),可能导致 OOM.

  6. OpenFlow Flow-Mod消息学习

    任务内容 1. 熟悉Flow-Mod消息触发场景. 2. 掌握Flow-Mod消息格式和常用字段含义. 实验原理 OpenFlow 协议支持3种消息类型:Controller-to-Switch(控制 ...

  7. Docker 入门篇

    Docker 简介 作为一种新兴的虚拟化方式,Docker 跟传统的虚拟化方式相比具有众多的优势. 更高效的利用系统资源 更快速的启动时间 一致的运行环境 持续交付和部署 更轻松的迁移 更轻松的维护和 ...

  8. .NET常用开发框架汇总

    分布式缓存框架:Microsoft Velocity:微软自家分布式缓存服务框架.Memcahed:一套分布式的高速缓存系统,目前被许多网站使用以提升网站的访问速度.Redis:是一个高性能的KV数据 ...

  9. linux通过expect工具来实现自动登录服务器,并执行相关操作

    参考地址:https://www.cnblogs.com/liyuanhong/articles/7728034.html EOF的使用参考:https://www.cnblogs.com/liyua ...

  10. [JDK8] Stream

    1 collect(toList()) collect(toList()) 方法由Stream 里的值生成一个列表,是一个及早求值操作. 2 map 如果有一个函数可以将一种类型的值转换成另外一种类型 ...