Getting Started with the Web-SpringBoot

Spring Boot web quick start

  • Requirements: Use Spring Boot to develop a web project. After the browser initiates a request /hello, return the string "Hello World~" to the browser
  • development steps
    • Create a SpringBoot project and check the relevant dependencies for web development
      • You can create modules according to the different versions of your idea
        • (Proceed to the next step after the basic information is set)
        • Select the required dependencies
    • Define the Hello Controller class, add the Hello method, and add comments
      • After the creation is complete, create a Controller class to handle the corresponding request
        • The specific code is as follows:
        • package com.example.Controller;
          
          import org.springframework.web.bind.annotation.RequestMapping;
          import org.springframework.web.bind.annotation.RestController;
          
          //请求处理类
          @RestController
          //它是@Controller的扩展,专门用于构建RESTful风格的Web服务。
          public class HelloController {
              // 设置处理的请求地址
              @RequestMapping("/hello")
              public String hello() {
                  System.out.println("Hello");
                  return "Hello World~";
              }
          }
          
    • Run the SpringBoot startup class to test the running results
      • The result of the operation is as follows:
      • (Web side)
      • (idea end)
  • As a java development framework, SpringBoot is essentially a java application. It has built-in many common configurations and default settings, which reduces the workload of developers on project configuration and makes the development process easier and more efficient.

Guess you like

Origin blog.csdn.net/weixin_64939936/article/details/131647077