dispatcherServlet-servlet.xml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
  7. <!--配置扫描的包-->
  8. <context:component-scan base-package="com"></context:component-scan>
  9. <!-- 配置强大的视图解析器-->
  10. <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  11. <!-- 前缀-->
  12. <property name="prefix" value="/WEB-INF/views/"></property>
  13. <!-- 后缀-->
  14. <property name="suffix" value=".jsp"></property>
  15. </bean>
  16. <!-- id不能随便指定,必须是multipartResolver-->
  17. <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  18. <!-- 默认字符集 utf-8-->
  19. <property name="defaultEncoding" value="UTF-8"></property>
  20. <!-- 通过spel表达式设置文件上传的大小 -1不限制-->
  21. <property name="maxUploadSize" value="#{1024*1024}"></property>
  22. </bean>
  23. <!-- 添加注解驱动 注意导以mvc结尾的包-->
  24. <mvc:annotation-driven></mvc:annotation-driven>
  25. <!-- 配置全局拦截器-->
  26. <!-- <mvc:interceptors>-->
  27. <!-- <bean id="myHandlerInterceptor" class="com.sf.conroller.myHandlerInterceptor"></bean>-->
  28. <!-- </mvc:interceptors>-->
  29. <!-- 配置拦截一个请求-->
  30. <mvc:interceptors>
  31. <mvc:interceptor>
  32. <mvc:mapping path="/book/getBook"/>
  33. <bean class="com.sf.conroller.myHandlerInterceptor"></bean>
  34. </mvc:interceptor>
  35. </mvc:interceptors>
  36. </beans>