Spring+Springmvc+Mybatis使用Maven对Web项目的搭建(二)

在上一篇文章中web配置文件中指定了对应的dispatcher-servlet的对应的文件位置,接下来我们就对dispatcher-servlet.xml文件进行配置
在配置过程中会不断的向maven的pom.xml配置文件中引用对应的jar包
SpringMvc的配置文件的作用时包含网站跳转逻辑的控制
在配置写配置信息的时候需要在pom.xml文件中配置对应的引用
<!--spring SpringMVC Web包-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
需要配置的信息:
1. 配置需要扫描的Controller的包
2.配置对应的视图解析器
3.配置两个标准代码
<!--两个标准的配置-->
<!--将springmvc不能处理的请求交给tomcat 如静态资源加载问题-->
<mvc:default-servlet-handler/>
<!--能支持springmvc更高级的一些功能,JSR303校验,快捷的ajax 映射请求-->
<mvc:annotation-driven/>

附上对应的配置文件:
<?xml version= "1.0"  encoding= "UTF-8" ?>
        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"
 
     <!--SpringMCVC的配置文件,包含网站跳转逻辑的控制,配置-->
     <context:component-scan base-package= "org.spring"  use- default -filters= "false" >
         <!--只扫描Controller-->
         <context:include-filter type= "annotation"  expression= "org.springframework.stereotype.Controller" ></context:include-filter>
     </context:component-scan>
 
 
     <!--配置视图解析器 方便页面的返回-->
     <!--<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >-->
         <!--<property name= "prefix"  value= "/WEB-INF/templates" ></property>-->
         <!--<property name= "suffix"  value= ".html" ></property>-->
     <!--</bean>-->
     <bean id= "layoutDialect"  class= "nz.net.ultraq.thymeleaf.LayoutDialect" ></bean>
 
     <!--thymeleaf视图解析器配置-->
     <bean id= "templateResolver"  class= "org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver" >
         <property name= "prefix"  value= "/WEB-INF/templates/"  />
         <property name= "suffix"  value= ".html"  />
         <property name= "templateMode"  value= "HTML5"  />
         <property name= "cacheable"  value= "true"  />
         <property name= "characterEncoding"  value= "UTF-8" />
     </bean>
     <bean id= "templateEngine"  class= "org.thymeleaf.spring4.SpringTemplateEngine" >
         <property name= "templateResolver"  ref= "templateResolver"  />
         <property name= "additionalDialects"  ref= "layoutDialect"  />
     </bean>
 
     <bean class= "org.thymeleaf.spring4.view.ThymeleafViewResolver" >
         <property name= "templateEngine"  ref= "templateEngine"  />
         <property name= "characterEncoding"   value= "UTF-8"  />
     </bean>
 
     <!--两个标准的配置-->
     <!--将springmvc不能处理的请求交给tomcat  如静态资源加载问题-->
     <mvc: default -servlet-handler/>
     <!--能支持springmvc更高级的一些功能,JSR303校验,快捷的ajax 映射请求-->
     <mvc:annotation-driven/>
 
</beans>
下一篇时Spring配置文件的详解
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值