Spring Mvc相关随笔
web.xml部分
1.欢迎界面
<welcome-file-list> <welcome-file>/views/login.jsp</welcome-file> </welcome-file-list>
2.字符编码过滤器
<filter> <filter-name>CharacterEncoding</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>CharacterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
3.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:springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
4.配置文件路径设置
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
springmvc-serlvet.xml部分
1.InternalResourceViewResolver 视图解析器
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/views/"></property> <property name="suffix" value=".jsp"></property> </bean>
2.注解包扫描器
<context:component-scan base-package="cn.xin.controller" />
3.基础配置和引入静态资源配置
方法一:
<mvc:annotation-driven /> <mvc:default-servlet-handler />
方法二:
<mvc:resources location="/js/" mapping="/js/**"/> <mvc:resources location="/css/" mapping="/css/**"/> <mvc:resources location="/images/" mapping="/images/**"/>
4.全局异常处理
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.RuntimeException">login</prop> </props> </property> </bean>
5.拦截器配置
1.针对HandlerMapper配置
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"> <property name="interceptors"> <list> <ref bean="hInterceptor1"/> <ref bean="hInterceptor2"/> </list> </property> </bean> <bean id="hInterceptor1" class="cn.com.mvc.interceptor.HandlerInterceptorDemo1"/> <bean id="hInterceptor2" class="cn.com.mvc.interceptor.HandlerInterceptorDemo2"/>
2.针对全局配置
<mvc:interceptors> <!-- 多个拦截器,顺序执行 --> <mvc:interceptor> <!-- /**表示所有url包括子url路径 --> <mvc:mapping path="/**"/> <bean class="cn.com.mvc.interceptor.HandlerInterceptorDemo1"/> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="cn.com.mvc.interceptor.HandlerInterceptorDemo2"/> </mvc:interceptor> </mvc:interceptors>
6.文件上传
<!-- 配置MultipartResolver,用于上传文件,使用spring的CommonsMultipartResolver --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="5000000"/> <property name="defaultEncoding" value="utf-8"/> </bean>
知识点部分
1.拦截器
1.实现HandlerInterceptor接口或者继承实现了该接口的类、实现WebRequestInterceptor接口或者继承实现了该接口的类2.HandlerInterceptor是针对请求的整个过程的,接口的方法中都含有response参数,而WebRequestInterceptor是针对请求的,接口的方法参数中没有response3.两种接口都含有三个方法:preHandle、postHandle、afterCompletion
2.Resetfule风格
1.url:/12.@RequestMapping设置路径:@RequestMapping(value="/xxxx/{id}",method={})3.@PathVariable指定参数:@PathVariable("id")Integer xxId
3.数据校验
...
Spring Mvc相关随笔的更多相关文章
- Spring MVC相关
配置文件说明 web.xml, spring配置文件 applicationContext.xml, spring配置文件, mybatis连接mysql配置文件 sql-map-config-mys ...
- Spring MVC 相关资料整理
来源于:http://www.cnblogs.com/ylhssn/p/4062757.html 1.概述 Spring MVC是一种基于Java实现MVC设计模式的请求驱动类型的轻量级Web框架,即 ...
- spring mvc相关问题
1: 基于注解的SpringMVC简单介绍 2: spring组件扫描<context:component-scan/>使用详解 3: springMvc 注解配置例子
- 深入分析Spring 与 Spring MVC容器
1 Spring MVC WEB配置 Spring Framework本身没有Web功能,Spring MVC使用WebApplicationContext类扩展ApplicationContext, ...
- spring mvc 快速入门
---------- 转自尚学堂 高淇 --------- Spring MVC 背景介绍 Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块.使用 Spring 可插入的 MVC ...
- 准备学习Spring MVC
这一系列笔记将带你一步一步的进入Spring MVC,高手勿喷. 首先你得安装以下的工具: JDK,虽然JDK8已经发布了一段时间了,但是由于我们并不会使用到里面的新特性,所以JDK6以上版本皆可以( ...
- Spring mvc web 配置
Spring Framework本身没有Web功能, Spring MVC使用WebApplicationContext类扩展ApplicationContext ,使得拥有web功能.那么,Spri ...
- Spring mvc 模式小结
http://www.taobaotesting.com/blogs/2375 1.spring mvc简介 Spring MVC框架是一个MVC框架,通过实现Model-View-Controlle ...
- Spring MVC + Spring MongoDB + Querydsl 通过maven整合实例
效果图 一共3个页面:注册页,欢迎页,用户列表页 很简单的例子,主要是为了把流程走通,没有各种验证. 注册页: 欢迎页: 用户列表页: 源码地址 https://github.com/lemonbar ...
随机推荐
- 使用python生成c文件模板
目标 完成一个python脚本,实现指定名字后,自动生成.c和.h的模板.例如: /** * @file epc.c * @author 陈维 * @version V01 * @date 2017. ...
- MaterialImageView
https://github.com/zhaozhentao/MaterialImageView
- Qt实现一个简单的TextEditor
使用QT实现简单的TextEditor: 首先在窗口添加部件TextEditor,并设置中文字符 MainWindow::MainWindow(QWidget *parent) : QMainWind ...
- grep命令使用技巧
grep如何实现全词查找例如:要查找name这个单词,反馈的查找结果不能包含namespace这样的模式,但是可以包含name()这样的模式,即要查找的单词两端不可以有其他的数字或者字母,但可以有空格 ...
- How to Use SFTP ?
Usage Build a SFTP session with your linux like server, e.g, by the tool "Xshell" or any y ...
- win7 32位下安装MySQL出现的---1067系统错误---问题及解决
每次安装数据库,总是出现这样那样的问题.如今记录下来,供日后參考咯.... 下载的是解压缩-zip版本号的.安装配置教程參照洪哥笔记文章-<MySQL-5.6.13解压版(zip版)安装配置教程 ...
- SSH常见错误
错误一: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml] ...
- transport transmission
运输层 transport layer 传输控制协议 transmission control protocol
- XML简单介绍及举例
可扩展标记语言(eXtensibleMarkup Language,简称XML).是一种标记语言.标记指计算机所能理解的信息符号.通过此种标记,计算机之间能够处理包括各种信息的文章等. 怎样定义这些标 ...
- Managing SQLite Database
Approach #1: Use a Singleton to Instantiate the SQLiteOpenHelper Declare your database helper as a s ...