spring boot注解

精髓:
1)、SpringBoot启动会加载大量的自动配置类
2)、我们看我们需要的功能有没有SpringBoot默认写好的自动配置类;
3)、我们再来看这个自动配置类中到底配置了哪些组件;(只要我们要用的组件有,我们就不需要再来配置了)
4)、给容器中自动配置类添加组件的时候,会从properties类中获取某些属性。我们就可以在配置文件中指定这 些属性的值;
xxxxAutoConfigurartion:自动配置类;
给容器中添加组件
//只有一个有参构造器的情况下,参数的值就会从容器中拿
public HttpEncodingAutoConfiguration(HttpEncodingProperties properties)
{
this.properties = properties;
}
@Bean //给容器中添加一个组件,这个组件的某些值需要从properties中获取

SpringMVC自动配置

  1. Spring MVC auto-configuration Spring Boot 自动配置好了SpringMVC
  2. 以下是SpringBoot对SpringMVC的默认配置:(WebMvcAutoConfiguration)
  3. Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans. 自动配置了ViewResolver(视图解析器:根据方法的返回值得到视图对象(View),视图对象决定如何 渲染(转发?重定向?))
  4. ContentNegotiatingViewResolver:组合所有的视图解析器的; 如何定制:我们可以自己给容器中添加一个视图解析器;自动的将其组合进来;
  5. Support for serving static resources, including support for WebJars (see below).静态资源文件夹路 径,webjars
  6. Static index.html support. 静态首页访问
  7. Custom Favicon support (see below). favicon.ico
  8. 自动注册了 of Converter , GenericConverter , Formatter beans.
  9. Converter:转换器; public String hello(User user):
  10. 类型转换使用Converter Formatter 格式化器; 2017.12.17===Date;

扩展SpringMVC
springmvc.xml:<mvc:view‐controller path="/hello" view‐name=“success”/>
mvc:interceptors
mvc:interceptor
<mvc:mapping path="/hello"/>
bean>
/bean>
</mvc:interceptor>
</mvc:interceptors>

springboot:
编写一个配置类(@Configuration),是WebMvcConfigurerAdapter类型;不能标注@EnableWebMvc; 既保留了所有的自动配置,也能用我们扩展的配置;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
	// TODO Auto-generated method stub
	registry.addViewController("/Dentmon2").setViewName("success");
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值