做网站用哪种语言好,wordpress判断,wordpress utc时间设置,ui设计难吗简介 
SpringMVC技术与Servlet技术功能等同#xff0c;均属于web层开发技术 
SpringMVC是一种基于java实现的MVC模型的轻量级Web框架 优点 使用简单,开发便捷(相比于Servlet) 灵活性强 入门案例 
第一步、导入SpringMVC与Servlet坐标 
?xml version1.0 encod…简介 
SpringMVC技术与Servlet技术功能等同均属于web层开发技术 
SpringMVC是一种基于java实现的MVC模型的轻量级Web框架 优点 使用简单,开发便捷(相比于Servlet) 灵活性强 入门案例 
第一步、导入SpringMVC与Servlet坐标 
?xml version1.0 encodingUTF-8?project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.cacb/groupIdartifactIdSpringMVC_demo1/artifactIdversion1.0-SNAPSHOT/versionpackagingwar/packagingpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingmaven.compiler.source1.8/maven.compiler.sourcemaven.compiler.target1.8/maven.compiler.target/propertiesdependenciesdependencygroupIdjavax.servlet/groupIdartifactIdjavax.servlet-api/artifactIdversion3.1.0/versionscopeprovided/scope/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion5.2.10.RELEASE/version/dependency/dependenciesbuildpluginsplugingroupIdorg.apache.tomcat.maven/groupIdartifactIdtomcat7-maven-plugin/artifactIdversion2.1/versionconfigurationport80/portpath//path/configuration/plugin/plugins/build/project 
第二步、创建SpringMVC控制类(等同于Servlet功能) 
package com.cacb.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;//定义controller使用Controller定义Bean
Controller
public class UserController {//设置当前操作的返回路径RequestMapping(/save)//设置当前路径的返回值类型ResponseBodypublic String save(){System.out.println(user saving!);return {module:SpringMVC};}
}第三步、初始化SpringMVC环境(同SPring环境)设定SpringMVC加载对应的Bean 
package com.cacb.config;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
//创建spring配置文件加载controller对应的bean
Configuration
ComponentScan(com.cacb.controller)
public class SpringMVCConfig {
}第四步、初始化Servlet容器加载SPringMVC环境并设置SpringMVC技术处理的请求 
package com.cacb.config;import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;//定义一个servlet容器启动的配置类在里面加载spring配置
public class ServletContainersInitConfig extends AbstractDispatcherServletInitializer {// 加载springMVC容器配置Overrideprotected WebApplicationContext createServletApplicationContext() {AnnotationConfigWebApplicationContext ctx  new AnnotationConfigWebApplicationContext();ctx.register(SpringMVCConfig.class);return ctx;}//设置哪些请求归属springMVC处理Overrideprotected String[] getServletMappings() {//所有请求归springmvc管理return new String[]{/};}//加载spring容器配置Overrideprotected WebApplicationContext createRootApplicationContext() {return null;}
} Bean加载控制  
Controller加载控制与业务Bean加载控制 
SpringMVC相关Bean 表现层Bean 
Spring控制的Bean 业务Bean(Service) 功能Bean(DataSource等) 
因功能不同为了避免Spring错误的加载到SpringMVC管理的Bean 加载Spring控制的Bean的时候要排除掉SpringMVC控制的Bean 
三种解决方式 方式一Spring加载的bean设定扫描范围为com.cacb排除掉controller包内的bean 方式二Spring加载的bean设定扫描范围为几个准范围例如servicedao包等 方式三不区分Spring与SpringMVC的环境加载到同一个环境中