SpringMVC环境配置
1.maven依赖spring-webmvc

2.web.xml配置DispatcherServlet

3.配置applicationContext.xml的mvc标记
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mv="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--
context:component-scan标签作用
在Spring IOC 初始化过程中,自动创建并管理com.spring及子包中
拥有以下注解的对象
@Repository 通常书写在dao与数据交互的类
@Service 业务逻辑类,放在xxxService类上
@Controller 控制器类
@Component 如果类不好区分类型,就可以使用Component
-->
<context:component-scan base-package="com.spring"/>
<!--启用Spring MVC的注解开发模式-->
<mvc:annotation-driven/>
<!--将图片/js/css等静态资源排除在外,可提高执行效率-->
<mvc:default-servlet-handler/>
</beans>
4.开发Controller控制器



浙公网安备 33010602011771号