web.xml 简记
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 简记的更多相关文章
- 如何用Java类配置Spring MVC(不通过web.xml和XML方式)
DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置方式, XML看起来太累, 冗长繁琐. 还好借助于Servl ...
- web.xml中welcome-file-list的作用
今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...
- web.xml中load-on-startup的作用
如下一段配置,熟悉DWR的再熟悉不过了:<servlet> <servlet-name>dwr-invoker</servlet-name> <ser ...
- springmvc配置文件web.xml详解各方总结(转载)
Spring分为多个文件进行分别的配置,其中在servlet-name中如果没有指定init-param属性,那么系统自动寻找的spring配置文件为[servlet-name]-servlet.xm ...
- Java web.xml 配置详解
在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是 ...
- web.xml中url-pattern的用法
目录结构: // contents structure [-] url-pattern的三种写法 servlet匹配原则 filter匹配原则 语法错误的后果 参考文章 一.url-pattern的三 ...
- 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是很 ...
- Web.xml配置详解之context-param
<context-param> <param-name></param-name> <param-value>></param-value& ...
- javaWeb项目中Web.xml的基本配置
这个地址写的非常好 ,欢迎大家访问 Å:http://www.cnblogs.com/hxsyl/p/3435412.html 一.理论准备 先说下我记得xml规则,必须有且只有一个根节点,大小写敏感 ...
随机推荐
- linux shell通配符及if语句判断
$# 是传给脚本的参数个数 $0 是脚本本身的名字$1 是传递给该shell脚本的第一个参数$2 是传递给该shell脚本的第二个参数$@ 是传给脚本的所有参数的列表$* 是以一个单字符串显示所有向脚 ...
- JumpServer1.0 服务搭建
JumpServer1.0 服务搭建 系统环境配置 setenforce 0 systemctl stop iptables.service systemctl stop firewalld.serv ...
- AtCoder瞎做第二弹
ARC 067 F - Yakiniku Restaurants 题意 \(n\) 家饭店,\(m\) 张餐票,第 \(i\) 家和第 \(i+1\) 家饭店之间的距离是 \(A_i\) ,在第 \( ...
- Miller_Rabbin&&Pollard_Rho 学习笔记
占坑,待填 I Intro 首先我们考虑这样一个问题 给定一个正整数\(p(p<=1e8)\),请判断它是不是质数 妈妈我会试除法! 于是,我们枚举$ \sqrt p$ 以内的所有数,就可以非常 ...
- P1177 【模板】快速排序(学完归并和堆排之后的二更)
P1177 [模板]快速排序 不用说,连题目上都标了是一道模板,那今天就来对能用到的许多排序方式进行一个总结: 选择排序 选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理 ...
- 爬虫四大金刚:requests,selenium,BeautifulSoup,Scrapy
一.简介爬虫 1.什么是爬虫 #1.什么是互联网? 互联网是由网络设备(网线,路由器,交换机,防火墙等等)和一台台计算机连接而成,像一张网一样. #2.互联网建立的目的? 互联网的核心价值在于数据的共 ...
- Linux进阶知识和命令
一.Linux目录结构 目录 说明 /lost found系统修复 /bin 二进制命令所在的目录. /boot 系统引导程序所需的文件目录.安装系统分区的时候一般单独要分一个boot分区,大小可谓1 ...
- linux date -s
修改linux的时间可以使用date指令 修改日期: 时间设定成2009年5月10日的命令如下: #date -s 05/10/2009 修改时间: 将系统时间设定成上午10点18分0秒的命令如下. ...
- ref、out参数
ref和out都是表示按引用传递.与指针类似,直接指向同一内存. 按值传递参数的方法永远不可能改变方法外的变量,需要改变方法外的变量就必须按引用传递参数. 传递参数的方法,在C语言里,用指针.在C#里 ...
- Hadoop记录-切换NN
一.第一种方法 重启namenode(1.1.1.1 1.1.1.2)重启standby节点:1.1hadoop-daemon.sh stop zkfchadoop-daemon.sh stop na ...