1.新建maven项目(打包成jar包

springboot入门实例

 

2.在pom.xml添加spring-boot-starter-web依赖,并更新

<parent>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-parent</artifactId>

      <version>1.5.9.RELEASE</version>

   </parent>

   <dependencies>

      <dependency>

          <groupId>org.springframework.boot</groupId>

          <artifactId>spring-boot-starter-web</artifactId>

      </dependency>

   </dependencies>

 

3.写一个控制器如下,然后写一个main方法,把程序跑起来:

@RestController  //相当于声明Controller - 提共restful 风格
@EnableAutoConfiguration  //自动配置,不需要写spring的配置文件
public class HelloController {
   @RequestMapping("hello")
   @ResponseBody
   public String hello(){
      return "hello spring boot:2019-10-15";
   }

   public static void main(String[] args) {
      //启动程序
      SpringApplication.run(HelloController.class,args);
   }
}

    public static void main(String[] args) {

         //启动程序

         SpringApplication.run(HelloController.class, args);

    }

}

 

4.在浏览器中访问http://localhost:8080/hello

springboot入门实例

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-11-28
  • 2021-11-19
  • 2021-11-26
  • 2021-06-11
  • 2021-10-08
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
  • 2021-11-04
  • 2021-07-16
相关资源
相似解决方案