Springboot MVC 自动配置

官方文档阅读

Web

Spring Boot provides auto-configuration for Spring MVC that works well with most applications.

The auto-configuration adds the following features on top of Spring’s defaults:

  • Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
  • Support for serving static resources, including support for WebJars (covered later in this document).
  • Automatic registration of ConverterGenericConverter, and Formatter beans.
  • Support for HttpMessageConverters (covered later in this document).
  • Automatic registration of MessageCodesResolver (covered later in this document).
  • Static index.html support.
  • Automatic use of a ConfigurableWebBindingInitializer bean (covered later in this document).

If you want to keep those Spring Boot MVC customizations and make more MVC customizations (interceptors, formatters, view controllers, and other features), you can add your own @Configuration class of type WebMvcConfigurer but without @EnableWebMvc.

如果您希望保留 Spring Boot MVC 定制并进行更多的 MVC 定制(拦截器、格式化程序、视图控制器和其他特性) ,可以添加您自己的 webmvcrer 类型的@Configuration 类,但不要添加@EnableWebMvc。

If you want to provide custom instances of RequestMappingHandlerMappingRequestMappingHandlerAdapter, or ExceptionHandlerExceptionResolver, and still keep the Spring Boot MVC customizations, you can declare a bean of type WebMvcRegistrations and use it to provide custom instances of

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot是一个用于简化Spring应用程序开发的框架,它基于Spring框架并提供了自动配置、快速开发和无需繁琐配置的特性。Spring Boot MVCSpring Boot中的一部分,它提供了一种简单而强大的方式来构建基于MVC模式的Web应用程序。 以下是使用Spring Boot MVC的步骤: 1. 添加Spring Boot MVC依赖:在项目的pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 2. 创建Controller类:在项目中创建一个Controller类,用于处理HTTP请求和响应。可以使用`@RestController`注解将类标记为控制器,并使用`@RequestMapping`注解指定请求的URL路径和HTTP方法。 3. 编写处理方法:在Controller类中编写处理HTTP请求的方法,可以使用`@GetMapping`、`@PostMapping`等注解来指定处理方法对应的URL路径和HTTP方法。 4. 返回响应:在处理方法中编写业务逻辑,并返回相应的数据或视图。可以使用`@ResponseBody`注解将方法的返回值直接作为响应体返回给客户端,或者返回一个视图名称,Spring Boot会根据视图解析器的配置来解析并渲染视图。 5. 运行应用程序:使用Spring Boot的启动类来运行应用程序,可以使用`@SpringBootApplication`注解标记启动类,并在`main`方法中调用`SpringApplication.run()`方法来启动应用程序。 下面是一个简单的示例: ```java @RestController @RequestMapping("/hello") public class HelloController { @GetMapping public String sayHello() { return "Hello, Spring Boot MVC!"; } } ``` 在上面的示例中,我们创建了一个名为`HelloController`的控制器类,使用`@RestController`注解标记为控制器,并使用`@RequestMapping`注解指定了请求的URL路径。在`sayHello()`方法中,我们返回了一个字符串作为响应体。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值