文章网建站,制作企业网站的版式,店铺设计素材,怎么建设阿里巴巴国际网站首页在学习过程中#xff0c;框架给我们最大的作用#xff0c;就是想让开发人员尽可能地只将精力放在具体业务功能的实现之上#xff0c;而对于各种映射关系的配置#xff0c;统统由框架来进行完成#xff0c;由此#xff0c;注解就很好的将映射功能进行实现#xff0c;并且…在学习过程中框架给我们最大的作用就是想让开发人员尽可能地只将精力放在具体业务功能的实现之上而对于各种映射关系的配置统统由框架来进行完成由此注解就很好的将映射功能进行实现并且替代配置文件让项目更加简洁。
SpringMVC框架配置文件中组件转化为注解方式
创建替代配置文件的核心配置类在配置类中使用不同的注解来替代不同的组件标签由此实现注解替代配置文件但是在Spring的配置文件web.xml中还要加载SpringMVC配置文件但是此时该配置文件被创建的核心配置所替代所以我们应该创建应该类来加载核心配置类在web.xml配置文件中加载创建的类由此来达到加载SpringMVC核心配置类的目的。
SpringMVC核心配置类 package com.example.Config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;Configuration
ComponentScan(com.example.Controller)
EnableWebMvc // 注解驱动、静态资源处理器、拦截器
public class SpringMVCConfig {Beanpublic CommonsMultipartResolver multipartResolver() {CommonsMultipartResolver commonsMultipartResolver new CommonsMultipartResolver();commonsMultipartResolver.setDefaultEncoding(utf-8);commonsMultipartResolver.setMaxUploadSize(5000);return commonsMultipartResolver;}
}加载上述核心配置类的类 package com.example.Config;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class MyAnnotationConfigWebApplicationContext extends AnnotationConfigApplicationContext {public MyAnnotationConfigWebApplicationContext() {super.register(SpringMVCConfig.class);}
}在web.xml配置文件中加载
明天再来p139希望明天可以结束战斗
DispatcherServlet加载核心配置类
消除web.xml配置文件