Spring Boot web开发

常用注解

@Controller
@RestController
@RequestMapping
@ResponseBody
@GetMapping
@PathVariable
@PostMapping
@RequestParam
@PutMapping
@DeleteMapping
三、更换Web容器

Spring boot web默认使用tomcat容器,可以更换为jetty

  1. 排除spring-boot-starter-tomcat
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  1. 加入spring-boot-starter-jetty

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
    
四、Spring Boot 访问静态资源
  1. src/main/webapp目录下,可以直接访问(org.springframework.boot.autoconfigure.web.ResourceProperties)
  2. 默认静态资源路径是:classpath:[/META-INF/resources/,/resources/,/static/,/public/]
  3. 可以通过spring.resources.staticLocations进行配置
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐