SpringMVC,Spring,MyBatis集成配置SpringMVC

时间:2026-02-14 21:33:08

1、配置组件扫描路径:

<context:component-scan base-package="com.gwolf">

  

  </context:component-scan>

SpringMVC,Spring,MyBatis集成配置SpringMVC

2、如果你的eclipse开发工具不能通过工具自动添加spring相关的namespace,请安装spring相关插件,下图相关的东西是安装插件才会出现的。

SpringMVC,Spring,MyBatis集成配置SpringMVC

3、SpringMVC不能扫描所有的组件,只让它扫描控制器的组件

<context:component-scan base-package="com.gwolf">

  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

  </context:component-scan>

SpringMVC,Spring,MyBatis集成配置SpringMVC

4、禁用掉组件扫描默认规则

<context:component-scan base-package="com.gwolf" use-default-filters="false">

  <context:include-filter type="annotation" 

  expression="org.springframework.stereotype.Controller"/>

  </context:component-scan>

SpringMVC,Spring,MyBatis集成配置SpringMVC

5、配置视图解析器,方便页面返回

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

  <property name="prefix" value="/WEB-INF/views/"></property>

  <property name="suffix" value=".jsp"></property>

  </bean>

SpringMVC,Spring,MyBatis集成配置SpringMVC

6、将springmvc不能处理的请求交给tomcat处理

<mvc:default-servlet-handler/>

SpringMVC,Spring,MyBatis集成配置SpringMVC

7、配置能支持springmvc更高级的一些功能,JSR303校验,快捷的ajax请求,映射动态请求

 <mvc:annotation-driven />

SpringMVC,Spring,MyBatis集成配置SpringMVC

© 2026 一点知道
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com