springmvc.xml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.cdxw.controller"></context:component-scan>
  9. <!--配置Thymeleaf视图解析器-->
  10. <bean id="viewResolver" class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
  11. <property name="order" value="1"></property>
  12. <property name="characterEncoding" value="UTF-8"></property>
  13. <property name="templateEngine">
  14. <bean class="org.thymeleaf.spring5.SpringTemplateEngine">
  15. <property name="templateResolver">
  16. <bean class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
  17. <!--视图前缀-->
  18. <property name="prefix" value="/WEB-INF/templates/"></property>
  19. <!--视图后缀-->
  20. <property name="suffix" value=".html"></property>
  21. <property name="templateMode" value="HTML5"></property>
  22. <property name="characterEncoding" value="UTF-8"></property>
  23. </bean>
  24. </property>
  25. </bean>
  26. </property>
  27. </bean>
  28. <!--开启mvc的注解驱动-->
  29. <mvc:annotation-driven/>
  30. <!--
  31. 视图控制器:为当前的请求直接设置视图名称实现页面跳转
  32. path:设置处理的请求地址
  33. view-name:设置请求地址所对应的视图名称
  34. 若设置视图控制器,则只有视图控制器所设置的请求会被处理,其他的请求将全部404
  35. 此时必须配置一个标签:<mvc:annotation-driven/>,开启mvc的注解驱动
  36. -->
  37. <mvc:view-controller path="/" view-name="index"></mvc:view-controller>
  38. </beans>